Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in readBin(private$socket, raw(), n = len) : invalid 'n' argument #23

Open
domvoe opened this issue Feb 6, 2023 · 3 comments
Open

Comments

@domvoe
Copy link

domvoe commented Feb 6, 2023

Many thanks sharing this package.

I already use it a while and randomly get the follwing error:
Error in readBin(private$socket, raw(), n = len) : invalid 'n' argument

The strange thing ist that this error is showing up randomly, i.e. when I run the same code 10 times in a row it can be that no error is showing up, but the next time each other request is showing the error.

Do you have an idea how this can happen? Your help is really appreciated.

Here is an example code snippet with reponse from the console:

library(rib)
wrap <- IBWrapSimple$new()
ic <- IBClient$new()
ic$connect(port=7500, clientId=1)
contract <- IBContract(symbol="GOOG", secType="STK", exchange="SMART", currency="USD")
ic$reqContractDetails(11, contract)
ic$checkMsg(wrap)
Error in readBin(private$socket, raw(), n = len) : invalid 'n' argument

@lbilli
Copy link
Owner

lbilli commented Feb 6, 2023

Difficult to say without a way to reproduce.
Here are some thoughts that first come to mind:

  • I typically see that error when TWS suddenly and unilaterally closes the connection.
    This used to be a common occurrence before TWS 10.16 due to violating pacing rules (e.g. generating more than 50 requests per second). However, since TWS 10.16 this shouldn't happen with default settings. More on pacing errors in this comment.

  • Other reasons might cause a disconnection. Check the DATA tab on the upper right corner of TWS to make sure the client is still connected.

  • Some other network hiccups might garble the incoming messages queue and put it in an irrecoverable state. By tracing back the very first error message that appears might give some clues on the origin of the problem.

If reporting back, additional information can be useful such as OS, TWS version, rib version and any other error messages.

@domvoe
Copy link
Author

domvoe commented Feb 9, 2023

Thanks a lot for your fast reply.

The last days I tested the TWS option which was referenced in the first bullet point. The system is now running more stable, but sometimes the error is still popping up.

I use Windows and the recent versions of TWS (10.20) and rib (0.19).
The random behaviour makes the debugging hard. But I will still try and let you know in case I find something relevant.

Again many thanks for your help.

@AndrewEndl
Copy link

I used to get this error when I tried to open a connection via ic$connect that was already open (e.g. had not been properly closed earlier) with the same parameters (clientId, port)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants