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

Calling connectWebSocket twice fails #2169

Closed
kerdemdemir opened this Issue Jun 1, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@kerdemdemir
Copy link

commented Jun 1, 2018

auto ws_url = URL("wss://stream.binance.com:9443/ws/ethbtc@aggTrade");
auto ws = connectWebSocket(ws_url);
if ( !ws.connected )
	return;

sleep(2.seconds);
ws_url = URL("wss://stream.binance.com:9443/ws/iotabtc@depth");
ws = connectWebSocket(ws_url);
if ( !ws.connected )
	return;	

This is a minimized version of my case. The first connect is successful. But after second
connectWebSocket(ws_url); I sometimes recieve :

-object.Exception@../../.dub/packages/vibe-d-0.8.3/vibe-d/tls/vibe/stream/openssl.d(352): Reading from TLS stream was unsuccessful with ret 0
??:? [0x61bd6e]
??:? [0x621732]
exception.d:421 [0x47fbb3]
exception.d:388 [0x412fcd]
openssl.d:352 [0x564d33]
openssl.d:244 [0x565b9a]
openssl.d:239 [0x565b3d]
openssl.d:237 [0x5671c9]
interfaceproxy.d-mixin-302:302 [0x4b161e]
interfaceproxy.d-mixin-302:302 [0x4b19b9]
interfaceproxy.d-mixin-191:191 [0x4b0241]
operations.d:362 [0x4b1ec6]
operations.d:142 [0x4b1d3f]
smtp.d:56 [0x4b1c03]
smtp.d:41 [0x4af633]
client.d:908 [0x4bfe75]
client.d:908 [0x4bc850]
client.d:513 [0x4b9a2f]
websockets.d:120 [0x552e5a]
BinanceHelper.d:286 [0x49ffcf]

And sometimes I recieve another error :

core.exception.AssertError@../../.dub/packages/eventcore-0.8.34/eventcore/source/eventcore/drivers/posix/driver.d(302): Overwriting notification callback.
??:? [0x61bd6e]
??:? [0x621732]
??:? [0x61b2f1]
driver.d:302 [0x5c65a9]
sockets.d:351 [0x5cc131]
net.d:564 [0x5a7b97]
net.d:176 [0x5a7d32]
async.d:85 [0x5a6818]
net.d:569 [0x5a65c1]
net.d:538 [0x5a6411]
interfaceproxy.d-mixin-302:302 [0x4b0c07]
interfaceproxy.d-mixin-191:191 [0x4b02a1]
openssl.d:1131 [0x56af9d]
??:? BIO_read [0x7862faab]
??:? [0x78988809]
??:? [0x7898a0ac]
??:? [0x78986c63]
openssl.d:244 [0x565bf5]
openssl.d:244 [0x565b82]
openssl.d:239 [0x565b3d]
openssl.d:237 [0x5671c9]
interfaceproxy.d-mixin-302:302 [0x4b161e]
interfaceproxy.d-mixin-302:302 [0x4b19b9]
interfaceproxy.d-mixin-191:191 [0x4b0241]
client.d:542 [0x4bbd7a]
client.d:511 [0x4b9978]
websockets.d:120 [0x552e5a]
BinanceHelper.d:286 [0x49ffcf]

What I am missing here ? I really need to be able to two sockets at the same time.

Best Regards
Erdem

@mab-on

This comment has been minimized.

Copy link

commented Jun 11, 2018

I ran into a quite similar issue.
I was able to resolve my issue by allowing connectWebSocket() to manage multiple WebSocket-connections to the same host.

But i think you will need to do ws.close() before applying a "new" connection on ws.

@kerdemdemir

This comment has been minimized.

Copy link
Author

commented Jun 15, 2018

But i think you will need to do ws.close() before applying a "new" connection on ws.

Is this restriction by protocol ? Because in my application I need to open ~40 sockets at the same time.

With your pushes now the simple case I send is working(God bless you man I am really blocked by that). But program still crushes time to time since I open more sockets. There is a separate issue which close() is causing a freeze but I opened another ticket about it

The current crush is can be seen below. But unfortunately I don't have a minimal example to present it. I will try to reproduce it with a minimal example

core.exception.AssertError@../../.dub/packages/vibe-core-1.4.0/vibe-core/source/vibe/core/net.d(575): Assertion failure

??:? [0x615dfe]
??:? [0x61b7c2]
??:? [0x61541d]
net.d:575 [0x5a0b2a]
net.d:538 [0x5a0801]
interfaceproxy.d-mixin-302:302 [0x4a9dd7]
interfaceproxy.d-mixin-191:191 [0x4a9471]
openssl.d:1134 [0x56538d]
??:? BIO_read [0xdd52daab]
??:? [0xdd886809]
??:? [0xdd8880ac]
??:? [0xdd884c63]
openssl.d:244 [0x55ffb5]
openssl.d:244 [0x55ff3d]
openssl.d:239 [0x55fefd]
openssl.d:237 [0x5615b9]
interfaceproxy.d-mixin-302:302 [0x4aa7ee]
interfaceproxy.d-mixin-302:302 [0x4aab89]
interfaceproxy.d-mixin-191:191 [0x4a8dc1]
wrapper.d:209 [0x578f7d]
wrapper.d:209 [0x579439]
websockets.d:766 [0x54e379]
task.d:557 [0x51ebf8]
task.d:575 [0x5aedea]
task.d:386 [0x5ae712]
??:? fiber_entryPoint [0x6188a1]
Program exited with code -6

@wilzbach

This comment has been minimized.

Copy link
Member

commented Jul 19, 2018

I will try to reproduce it with a minimal example

Did you ever manage to do so?
DustMite can help you with this, if you can formulate a tester bash script.

s-ludwig added a commit that referenced this issue Feb 17, 2019

s-ludwig added a commit that referenced this issue Feb 17, 2019

Use requestHTTP for the non-scoped connectWebSocket. Fixes #2169.
This change required a rework of how the connection close and resource management is done to avoid InvalidMemoryOperationError. As a side-effect, this also fixes a leak of TCP connections for connectWebSocket.

The rework in particular makes sure that HTTPClientResponse.disconnect and HTTPServerResponse.finalize is called, and only called from the task that created the web socket. This makes sure that the HTTP client instance is properly returned to the connection pool after the web socket is closed.

Closes #2172.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.