-
Notifications
You must be signed in to change notification settings - Fork 51
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
transport.readLine seems to be blocking forever when socket closed. #8
Comments
|
Hey, Sorry I meant any reply server. A simple example may be for now the output is:
Below is the code which assumes that you run that netcat from above: import asyncdispatch2
var transport: StreamTransport
proc looper() {.async.} =
while true:
echo "Waiting for data"
var data = await transport.readLine()
if data.len == 0:
echo "No data, disconnected(?)"
echo "Got data ", data
if isMainModule:
proc demo() {.async.} =
transport = await connect(resolveTAddress("127.0.0.1:12345")[0])
asyncCheck looper()
echo "post looper"
await sleepAsync(1)
close(transport)
echo "Closed"
waitFor demo()
runForever() as you can see you never end up in "No data" part. |
1 similar comment
Hey, Sorry I meant any reply server. A simple example may be for now the output is:
Below is the code which assumes that you run that netcat from above: import asyncdispatch2
var transport: StreamTransport
proc looper() {.async.} =
while true:
echo "Waiting for data"
var data = await transport.readLine()
if data.len == 0:
echo "No data, disconnected(?)"
echo "Got data ", data
if isMainModule:
proc demo() {.async.} =
transport = await connect(resolveTAddress("127.0.0.1:12345")[0])
asyncCheck looper()
echo "post looper"
await sleepAsync(1)
close(transport)
echo "Closed"
waitFor demo()
runForever() as you can see you never end up in "No data" part. |
The same applies when you change var data = await transport.read(6) and netcat with |
In the same time code written in std asyncdispatch works fine (it's bit different but I hope it's equivalent): import asyncnet, asyncdispatch
var sock: AsyncSocket
proc looper() {.async.} =
while true:
echo "Waiting for data"
var data = await sock.recvLine()
if data.len == 0 or data == "\r\L":
echo "No data, disconnected(?)"
return
echo "Got data ", data
if isMainModule:
proc demo() {.async.} =
sock = newAsyncSocket()
await sock.connect("127.0.0.1", 12345.Port)
echo "post connect"
asyncCheck looper()
echo "post looper"
await sleepAsync(100)
sock.close()
echo "Closed"
await sleepAsync(10000)
waitFor demo()
runForever() |
@pigmej what OS you are use? |
Arch Linux with 4.17 kernel. |
@pigmej Your current sample uses 2 problems. |
@cheatfate agree but if you will connect that against nats.io:
In the same time it can handle properly both cases. What are the flaws btw? (besides these from README).
That's fair but both situations that we're having in this issue are fundamental flaws in ad2, isn't it? I reached to ad2 because I was aware that ad from stdlib is far from being perfect. |
@pigmej i'm working on fixes. |
The only way to avoid this bugs in future is to make |
Sounds reasonable. But a name |
Fix Unix connection failed bug.
Consider following example:
If you will run it against any "echo" server running on localhost:5000 you should see:
I'm pretty sure that readLine should return empty read when socket is closed especially that https://github.com/status-im/nim-asyncdispatch2/blob/f4f98d617c067ed590d7cd2fd761134d81376a1b/asyncdispatch2/transports/stream.nim#L1069 says that it should read whatever have been left when EOF received.
The text was updated successfully, but these errors were encountered: