Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

uv_connect_cb() is called with status=0 if data is writen #443

Closed
ibc opened this issue Jun 3, 2012 · 4 comments
Closed

uv_connect_cb() is called with status=0 if data is writen #443

ibc opened this issue Jun 3, 2012 · 4 comments

Comments

@ibc
Copy link
Contributor

ibc commented Jun 3, 2012

(Linux)

Hi, let me explain this strange case with pseudo-code:

addr = 127.0.0.1:9999
# Nothing is listening in 127.0.0.1:9999 so ECONNREFUSED should occur.
uv_tcp_connect(connect_req, handle, addr, connect_cb);

# Right now attempt to write:
uv_write(write_req, handle, "HELLO", write_cb);

So the result of this code is that connect_cb() is called with status=0 (so connected), then write_cb() is called with error ECONNREFUSED, and then connect_cb() is called again with error EOF.

So, what I think is that the connection was established but inmediately disconnected by the peer, which is not true!

Thus my basic question is: is the above code wrong? is it valid (in UV land) to attemp to write in a TCP handle before it's connected? Why does the above code call to connect_cb() with status 0?

@ibc
Copy link
Contributor Author

ibc commented Jun 3, 2012

If I replace the destination IP of the above pseudo-code to "1.2.3.4" (so ETIMEDOUT happens) it works "as expected":

  • connect_cb()is called with error ETIMEDOUT, so I call to uv_close().
  • write_cb() is then called with EINTR error.

@bnoordhuis
Copy link
Contributor

I can look into it. Can you post a complete test case?

@ibc
Copy link
Contributor Author

ibc commented Jun 4, 2012

Hi, I've tryed to add a test unit showing this but I get some ugly error during the test execution. Anyhow I've added some printf which demostrate the issue.

The code is here: https://gist.github.com/2865591

After inserting it within UV test units I get this result:

tcp_dont_call_connect_status_0_after_write_when_connection_fails
`tcp_dont_call_connect_status_0_after_write_when_connection_fails` failed: exit code 11
Output from process `tcp_dont_call_connect_status_0_after_write_when_connection_fails`:
--- connect_cb(status = 0)
--- write_cb(status = -1)

@bnoordhuis
Copy link
Contributor

Fixed (on Unices) in cb9ca14.

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

No branches or pull requests

2 participants