Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

[Question]How to detect pipe(obtained from ctx->connect()) is writable? #420

Open
Rhett-Ying opened this issue Dec 19, 2021 · 6 comments
Open

Comments

@Rhett-Ying
Copy link

Hi,

when I get a pipe via ctx->context(address), how do I know the pipe is ready for write or read? A return from ctx->connect() does not mean the connection has been built, right? If I call pipe->write() immediately, such write could fail as the underlying connection has not built yet.

@lw
Copy link
Contributor

lw commented Dec 20, 2021

A pipe is always immediately writable, and the pipe might "hold onto" your write requests for a bit until the connections are ready, but this is invisible to you.

@Rhett-Ying
Copy link
Author

oh, I do hit error when write immediately. something wrong in my code? could you help take a look?

My scenario is CLIENT triggers connection before SERVER starts to listen. In the write callback, sometimes error is evaluated as true.

CLIENT:
std::shared_ptr<Pipe> pipe; pipe = context->connect(addr); auto done = std::make_shared<std::promise<bool>>(); tensorpipe::Message tpmsg; tpmsg.metadata = "connect"; pipe->write(tpmsg, [done](const tensorpipe::Error &error) { if (error) { LOG(WARNING) << "Error occurred when write to pipe: " << error.what(); done->set_value(false); } else { done->set_value(true);

LOG:
Error occurred when write to pipe: ECONNREFUSED: connection refused (this error originated at tensorpipe/transport/uv/connection_impl.cc:62)

@Rhett-Ying
Copy link
Author

Additional info for my scenario: I used same TensorPipe::Context instance to connect to multiple servers, namely I have called context->connect() multiple times and obtained multiple pipes. I think it's a normal use case, right? Alternatively, we could create TP::Context for each connection.

@lw
Copy link
Contributor

lw commented Dec 20, 2021

A "connection refused" means that the server isn't listening on that address/port, you should check how you're obtaining that address, it should come from the server's Listener instance.

@Rhett-Ying
Copy link
Author

If I keep calling auto pipe = context->connect();pipe->write() until write successfully in client side, will I hit any potential resource leak or run out issue? Just assume the server starts listen a quite long time later.

@eedalong
Copy link

eedalong commented Feb 16, 2022

If I keep calling auto pipe = context->connect();pipe->write() until write successfully in client side, will I hit any potential resource leak or run out issue? Just assume the server starts listen a quite long time later.

@Rhett-Ying I guess there will be no harm cuz message sending requires both client and server come into play. Write operation will not finish if receiver doesnt issue a read operation. So if server is not ready to issue read opreation and you call pipe->write, this operation will be stucked

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

3 participants