Keyboard Shortcuts
Likes
Search
Error 509 - exception caught while reading socket - no such file or directory
Folks,
I've been running TWS 943.1b (30 Dec 2013) with C++ API 9.68 for the past 1.5 years, without trouble. My app hasn't changed either. This morning, I get repeated disconnects due to error 509 - exception caught while reading socket. Has IB changed anything on their side, and do others have similar troubles ? Cheers souqMate. |
Spot on! Or almost. Here's the error handler from EposixClientSocket.cpp:
bool EPosixClientSocket::handleSocketError() { // no error if( errno == 0) return true; // Socket is already connected if( errno == EISCONN) { return true; } if( errno == EWOULDBLOCK) return false; if( errno == ECONNREFUSED) { getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); } else { getWrapper()->error( NO_VALID_ID, SOCKET_EXCEPTION.code(), SOCKET_EXCEPTION.msg() + strerror(errno)); } // reset errno errno = 0; eDisconnect(); return false; } Now the variables are EISCONN=106, EWOULDBLOCK=11, ECONNREFUSED=111; I have errno=2, which makes me jump to the end and call eDisconnect(). Question: what's errno=2 and why do I get it after 1.5 or even 3 years ? Has IB introduced it overnight? (Yet this socket communication depends only on TWS and API, i.e. independent of IB's servers). I can't believe I'm the only person affected. Thanks for your input! SouqMate. ---In TWSAPI@..., <no_reply@...> wrote : Check to see if your socket read() is returning EWOULDBLOCK error. This may be terminating your connection prematurely. |
开云体育errno =2?#define ENOENT?????????? 2????? /* No such file or directory */ Not sure why this error would be set, I don't see the code you've referenced below in my EPosixClientSocket.cpp - I'm using the version from twsapi, which is probably newer than your code. On 15/07/15 19:17, souqmate@...
[TWSAPI] wrote:
Spot on! Or almost. Here's the error handler from EposixClientSocket.cpp: bool EPosixClientSocket::handleSocketError() { // no error if( errno == 0) return true; // Socket is already connected if( errno == EISCONN) { return true; } if( errno == EWOULDBLOCK) return false; if( errno == ECONNREFUSED) { getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); } else { getWrapper()->error( NO_VALID_ID, SOCKET_EXCEPTION.code(), SOCKET_EXCEPTION.msg() + strerror(errno)); } // reset errno errno = 0; eDisconnect(); return false; } Now the variables are EISCONN=106, EWOULDBLOCK=11, ECONNREFUSED=111; I have errno=2, which makes me jump to the end and call eDisconnect(). Question: what's errno=2 and why do I get it after 1.5 or even 3 years ? Has IB introduced it overnight? (Yet this socket communication depends only on TWS and API, i.e. independent of IB's servers). I can't believe I'm the only person affected. Thanks for your input! SouqMate. ---In TWSAPI@..., wrote : Check to see if your socket read() is returning EWOULDBLOCK error. This may be terminating your connection prematurely. ------------------------------------ Posted by: souqmate@... ------------------------------------ ------------------------------------ Yahoo Groups Links <*> To visit your group on the web, go to: <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: (Yahoo! ID required) <*> To change settings via email: TWSAPI-digest@... TWSAPI-fullfeatured@... <*> To unsubscribe from this group, send an email to: TWSAPI-unsubscribe@... <*> Your use of Yahoo Groups is subject to: -- Stewart Douglas sdouglas@... |
Thanks! I didn't even know these error numbers were universal for unix!
toggle quoted message
Show quoted text
What do you mean by "the version from twsapi"? Do you mean Jan Boonen's TwsApiC++ ( ?? But this one too has the same code I pasted,? see file source/PosixClient/src/EPosixClientSocket.cpp. And IB's API_9.71 has the same snippet as in API_9.68, so I doubt using the latest API version will resolve issues. What could cause these messy errors nb 2 ? S ---In TWSAPI@..., <sdouglas@...> wrote :
errno =2? #define ENOENT?????????? 2????? /* No such file or directory */ Not sure why this error would be set, I don't see the code you've referenced below in my EPosixClientSocket.cpp - I'm using the version from twsapi, which is probably newer than your code. On 15/07/15 19:17, souqmate@...
[TWSAPI] wrote: Spot on! Or almost. Here's the error handler from EposixClientSocket.cpp: bool EPosixClientSocket::handleSocketError() { // no error if( errno == 0) return true; // Socket is already connected if( errno == EISCONN) { return true; } if( errno == EWOULDBLOCK) return false; if( errno == ECONNREFUSED) { getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); } else { getWrapper()->error( NO_VALID_ID, SOCKET_EXCEPTION.code(), SOCKET_EXCEPTION.msg() + strerror(errno)); } // reset errno errno = 0; eDisconnect(); return false; } Now the variables are EISCONN=106, EWOULDBLOCK=11, ECONNREFUSED=111; I have errno=2, which makes me jump to the end and call eDisconnect(). Question: what's errno=2 and why do I get it after 1.5 or even 3 years ? Has IB introduced it overnight? (Yet this socket communication depends only on TWS and API, i.e. independent of IB's servers). I can't believe I'm the only person affected. Thanks for your input! SouqMate. ---In TWSAPI@..., <no_reply@...> wrote : Check to see if your socket read() is returning EWOULDBLOCK error. This may be terminating your connection prematurely. ------------------------------------ Posted by: souqmate@... ------------------------------------ ------------------------------------ Yahoo Groups Links <*> To visit your group on the web, go to: <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: (Yahoo! ID required) <*> To change settings via email: TWSAPI-digest@... TWSAPI-fullfeatured@... <*> To unsubscribe from this group, send an email to: TWSAPI-unsubscribe@... <*> Your use of Yahoo Groups is subject to:-- Stewart Douglas sdouglas@... |
OK, if I ignore these messages, my trading app works as before - at least on demo account with API_9.68.
toggle quoted message
Show quoted text
I'll try tomorrow on my real account. I've merely added into EPosixClientSocket::handleSocketError(): if( errno == ENOEOT) return true; // errno=2, no file or directory. Pray it won't ruin my production.? I'm walking blind, here. Cheers, S. ---In TWSAPI@..., <souqmate@...> wrote : Thanks! I didn't even know these error numbers were universal for unix! What do you mean by "the version from twsapi"? Do you mean Jan Boonen's TwsApiC++ ( ?? But this one too has the same code I pasted,? see file source/PosixClient/src/EPosixClientSocket.cpp. And IB's API_9.71 has the same snippet as in API_9.68, so I doubt using the latest API version will resolve issues. What could cause these messy errors nb 2 ? S ---In TWSAPI@..., <sdouglas@...> wrote :
errno =2? #define ENOENT?????????? 2????? /* No such file or directory */ Not sure why this error would be set, I don't see the code you've referenced below in my EPosixClientSocket.cpp - I'm using the version from twsapi, which is probably newer than your code. On 15/07/15 19:17, souqmate@...
[TWSAPI] wrote: Spot on! Or almost. Here's the error handler from EposixClientSocket.cpp: bool EPosixClientSocket::handleSocketError() { // no error if( errno == 0) return true; // Socket is already connected if( errno == EISCONN) { return true; } if( errno == EWOULDBLOCK) return false; if( errno == ECONNREFUSED) { getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg()); } else { getWrapper()->error( NO_VALID_ID, SOCKET_EXCEPTION.code(), SOCKET_EXCEPTION.msg() + strerror(errno)); } // reset errno errno = 0; eDisconnect(); return false; } Now the variables are EISCONN=106, EWOULDBLOCK=11, ECONNREFUSED=111; I have errno=2, which makes me jump to the end and call eDisconnect(). Question: what's errno=2 and why do I get it after 1.5 or even 3 years ? Has IB introduced it overnight? (Yet this socket communication depends only on TWS and API, i.e. independent of IB's servers). I can't believe I'm the only person affected. Thanks for your input! SouqMate. ---In TWSAPI@..., <no_reply@...> wrote : Check to see if your socket read() is returning EWOULDBLOCK error. This may be terminating your connection prematurely. ------------------------------------ Posted by: souqmate@... ------------------------------------ ------------------------------------ Yahoo Groups Links <*> To visit your group on the web, go to: <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: (Yahoo! ID required) <*> To change settings via email: TWSAPI-digest@... TWSAPI-fullfeatured@... <*> To unsubscribe from this group, send an email to: TWSAPI-unsubscribe@... <*> Your use of Yahoo Groups is subject to:-- Stewart Douglas sdouglas@... ? |
开云体育I found them in /usr/include/asm-generic/errno-base.h on my box (Debian)I'm using the codebase from Rudi (). Having checked through the code, I've realised that the code you are referring to is only on one of the original IB branches, so I need to check why it was removed, I don't think that is something I've done in my changes - I've merged the latest 9.71 code into my local copy in a separate branch). I've never seen errno 2 coming back from a socket call, unless possibly you're somehow using a bad fd, or the errno is getting set by a system call in another thread. If you're still managing to get responses from IB etc, then I guess your change is ok - but it does feel fishy to me. Have you made any other changes recently to you code ? Cheers Stew On 15/07/15 22:11, souqmate@...
[TWSAPI] wrote:
Thanks! I didn't even know these error numbers were universal for unix! -- Stewart Douglas sdouglas@... |
mochasatin
Glad I could help. I Ran into this problem when I upgraded from Qr4.8 to Qt5.0. The Qt upgrade simply exacerbated the problem that had already existed in the way I was using the API. The EWOULDBLOCK error is set when the receive buffer is empty and a read is attempted. Since I am using a nonblocking read, the appropriate response in my case was to simply return TRUE in the error handler and then reread the socket, not terminate the connection. In your case an errno=2 is ENOENT- no such file or directory. Which sounds like your file descriptor is invalidated prior to reading maybe??? Try catching the ENOENT error and returning TRUE to see if it leads to other errors. Check for similar errors in the send routine.
Scott |
Hi souqmate, I'm very interested to find out what the real cause might be. I get error 509 a lot and I spend a lot of time debugging my code. This error?code is highly sensitive to my own memory corruption bugs. I must have had over different 20 bugs leading to error 509 which I've addressed, and for me that means it simply runs longer before it gets that error again. I've used some debugging tools to help figure out?what to fix, but usually?the brute force method?(containment) is what has worked for me.?Not sure if this is helpful to you but I?have found that how long it takes for?error 509?to occur?in my program?varies from seconds to weeks, depending on the bug. I don't know enough to say what the upper limit is, in practice, for how long a bug in your code might take to appear. Not saying that it's your bug, but curious when was the last time you made changes to your code? Once, I found that more recent changes to my code unearthed a problem that had existed from a long time ago... |
Nick
开云体育I haven't been following this thread in detail but I wanted to say that "no such file or directory" is not a possible error from the Windows socket read function (recv).The recv() function does not return this error code and none of the Winsock error codes (WSA...) map to ENOENT (defined as 2). If ENOENT is being encountered during socket read processing then the error originates somewhere else, not with the actual socket reading. It sounds like error handling in some other part of the code is not processing the ENOENT and it winds up being encountered in the socket read code but didn't actually occur there. There are many ways in Windows to implement socket reads but still none of the WSA errors map to ENOENT. I'm not a .Net person and my comments here apply to the Windows api itself. It may be that .Net has an entirely different way of mapping error codes but still "no such file or directory" does not make sense in the context of a socket read. On 7/17/2015 12:41 PM,
adamr9292@... [TWSAPI] wrote:
? |
Thanks, Adam and Nick, for your insights.
toggle quoted message
Show quoted text
I still haven't figured out what exactly happened.? The fix with ignoring ENOENT errors worked well for the real account as for the demo account.? In the mean time, my old executable (which wasn't amended to ignore ENOENT) works again fine (no disconnects).? Really weired! So these ENOENT messages would have infested my socket for two days (roughly 1 per second) only to vanish as they came. Adam, I share your view that tiny changes may uncover deeper bugs, but I I haven't touched the core of my code (3 yrs old); I only added models. I can't efficiently investigate now, as I'm on holidays, launching production every morning remotely via VNC or NX.? But I'm starting to think that these spurious ENOENT messages are due to some hacker's program abusing of my socket. I noticed that my machine had been hacked by brute force two days earlier (I'd forgotten to close port 22, and one of the fifty hackers guessed my password within 10 hours - from my /var/logs/auth.log).? Now that I've kept intruders at bay, it seems I get no more ENOENT troubles.?? I still have to find out what exactly the hacker did on my linux box. But perhaps he did nothing and I'm on a wrong path. I'll keep you posted. souqMate ---In TWSAPI@..., <news1000@...> wrote :
I haven't been following this thread in detail but I wanted to say
that "no such file or directory" is not a possible error from the
Windows socket read function (recv). The recv() function does not return this error code and none of the Winsock error codes (WSA...) map to ENOENT (defined as 2). If ENOENT is being encountered during socket read processing then the error originates somewhere else, not with the actual socket reading. It sounds like error handling in some other part of the code is not processing the ENOENT and it winds up being encountered in the socket read code but didn't actually occur there. There are many ways in Windows to implement socket reads but still none of the WSA errors map to ENOENT. I'm not a .Net person and my comments here apply to the Windows api itself. It may be that .Net has an entirely different way of mapping error codes but still "no such file or directory" does not make sense in the context of a socket read. On 7/17/2015 12:41 PM,
adamr9292@... [TWSAPI] wrote: ? |
static const CodeMsgPair SOCKET_EXCEPTION(509, "Exception caught while reading socket - "); Whenever the TWS library encounters an error while parsing the socket data OR whenever the user code (your code) in EWrapper throws an exception, the TWS library raises his error and stops the parsing the socket. This is misleading as an exception thrown in user code probably has nothing to do with the socket. For that reason, the TwsApiC++ ()?layer around the default TWS posix C++ library catches exceptions thrown from user code, and reports them back via an extra method in its EWrapperL0: virtual void OnCatch( const char* MethodName, const long Id ) The Id can be the tickerId, reqId, orderId, or NO_VALID_ID (-1) when no Id is available. You can overload this method of course. Maybe the method could give more detail on the exception then it does now. Have fun with it. Jan ---In twsapi@..., <adamr9292@...> wrote : Hi souqmate, I'm very interested to find out what the real cause might be. I get error 509 a lot and I spend a lot of time debugging my code. This error?code is highly sensitive to my own memory corruption bugs. I must have had over different 20 bugs leading to error 509 which I've addressed, and for me that means it simply runs longer before it gets that error again. I've used some debugging tools to help figure out?what to fix, but usually?the brute force method?(containment) is what has worked for me.?Not sure if this is helpful to you but I?have found that how long it takes for?error 509?to occur?in my program?varies from seconds to weeks, depending on the bug. I don't know enough to say what the upper limit is, in practice, for how long a bug in your code might take to appear. Not saying that it's your bug, but curious when was the last time you made changes to your code? Once, I found that more recent changes to my code unearthed a problem that had existed from a long time ago... ? |
To close this topic, I conclude that the mysterious appearance of ENOENT errors on my socket are probably due to a hacker using my socket to spam the planet.
I'm not sure what the hacker did, as the ssh session broke off after 3 min of idleness, preventing the shell to update the .bash_history file.? The checksum of system binary files was correct and the rootkit hunter rkhunter didn't see anything suspicious.? The /var/log/auth were unchanged and showed that following IPs guessed my crappy password by brute force (I also forgot to close port 22): 93.62.1.201 (Milan) on 20150807 at 22:33:20 after 769 attempts in 31 minutes (never logged in again) 93.174.93.69 (www.ecatel.net, The Hague) on 20150710 at 17:12:55 after 327 attempts in 17 minutes (logged in 31 times again till 20150716). It seems the hacker only left behind a few files in /tmp/ and in my home dir, of which a nasty obfuscated perl script, see which can be partially decoded by pasting it into I've no idea what that script does.? It seems to be a mailer/spammer (postfix) and to want to install an apache server (httpd). There's also a lot of mention of sockets.? So I suppose the hacker's monkey business was responsible for the ENOENT errors caught by my TWSAPI. And when I secured my machine two days later and uninstalled the postfix agent, the ENOENT messages disappeared. So thank IB, whose api helped warn me of hackers ;) All's well that ends well (hopefully). souqMate ? ---In TWSAPI@..., <jan.boonen@...> wrote : static const CodeMsgPair SOCKET_EXCEPTION(509, "Exception caught while reading socket - "); Whenever the TWS library encounters an error while parsing the socket data OR whenever the user code (your code) in EWrapper throws an exception, the TWS library raises his error and stops the parsing the socket. This is misleading as an exception thrown in user code probably has nothing to do with the socket. For that reason, the TwsApiC++ ()?layer around the default TWS posix C++ library catches exceptions thrown from user code, and reports them back via an extra method in its EWrapperL0: virtual void OnCatch( const char* MethodName, const long Id ) The Id can be the tickerId, reqId, orderId, or NO_VALID_ID (-1) when no Id is available. You can overload this method of course. Maybe the method could give more detail on the exception then it does now. Have fun with it. Jan ---In twsapi@..., <adamr9292@...> wrote : Hi souqmate, I'm very interested to find out what the real cause might be. I get error 509 a lot and I spend a lot of time debugging my code. This error?code is highly sensitive to my own memory corruption bugs. I must have had over different 20 bugs leading to error 509 which I've addressed, and for me that means it simply runs longer before it gets that error again. I've used some debugging tools to help figure out?what to fix, but usually?the brute force method?(containment) is what has worked for me.?Not sure if this is helpful to you but I?have found that how long it takes for?error 509?to occur?in my program?varies from seconds to weeks, depending on the bug. I don't know enough to say what the upper limit is, in practice, for how long a bug in your code might take to appear. Not saying that it's your bug, but curious when was the last time you made changes to your code? Once, I found that more recent changes to my code unearthed a problem that had existed from a long time ago... ? ? |
This sounds like it wasn't your case.... but I had the same error this morning. ?I was looking left and right and all over for the problem, when all of a sudden my program started throwing out trades. ?It turns out that ubuntu or linux can have a bug where the terminal window (the little black window) disappears when you minimize it. ?I noticed that the terminal window that was showing my program was suddenly gone... so I assumed my program had crashed and I tried starting the program again, and of course it didn't work because it was in fact already running!
So, for future reference, if you are running linux and you get this 509 error, press the special windows button + w ?and you will see all the currently running programs. ?Here's a link for more info:?https://askubuntu.com/questions/167054/terminal-window-disappears-after-i-minimize-it |