Skip to content

Conversation

@mikolajpp
Copy link
Contributor

@mikolajpp mikolajpp commented Oct 10, 2025

It is presently impossible to interface with conn using the typical pattern of sending a command using one program, and receiving the result with another through Unix pipes. Conn will eagerly close the connection as soon as it hears EOF from the read end of the pipe, which does not leave any chance to deliver an future result to the recipient. The only way to reliably receive results from conn in this situation is to set long timeouts in tools such as netcat or socat.

This PR is (1) request for clarification about the protocol, whether the original behavior was intended, and (2) a first attempt to rectify this situation by:

  1. Only closing the read end of the pipe on genuine errors in newt.c
  2. Closing the channel after the result has been delivered, if the read end of the channel's pipe had reached EOF.

This PR requires an expert's look whether this change fits well with other IO drivers, given that newt.c is used in many other places.

With this PR applied, I have been able to successfully use socat with the click script to dramatically speedup interactions with an Urbit ship via conn.

Our backend tests runner now completes in under 20s, while previously it took more than 4m to complete, due to a need for long timeouts at each interaction.

mikolajpp and others added 3 commits October 10, 2025 14:13
Conn protocol closes the channel as soon as an EOF is received
from a read request. This is at odds with a typical usage of conn,
where separate programs are used to send a command and receive a result.

We modify this behavior by calling moat `bal_f` only on genuine read errors.
Furthermore, in conn.c we close the channel after processing the effect
if we detect that the read end of the pipe has closed.
@mikolajpp mikolajpp requested a review from a team as a code owner October 10, 2025 06:35
@mikolajpp
Copy link
Contributor Author

mikolajpp commented Oct 10, 2025

This change also works well with standard netcat, when supplied with a timeout option. netcat -w 300 (...) as used by click would wait up to 300s for a response from conn, but close the connection as soon as a result is received, which is the desired behavior we are trying to achieve here.

@mikolajpp mikolajpp changed the title conn: robustly deliver results after channel read EOF conn: robustly deliver response after channel read EOF Oct 10, 2025
@joemfb
Copy link
Collaborator

joemfb commented Nov 12, 2025

This change seems right for conn, but not the behavior we want for mars/urth IPC. In the long run, I don't think both of those things should use newt, but for now it'd be a bit of work to detangle them. I've pushed up a hacky workaround to preserve the old IPC behavior (see bcb965a), can you take a look and make sure it's still suitable for your needs?

@mikolajpp
Copy link
Contributor Author

I have tested with your changes, works just as good.

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

Successfully merging this pull request may close these issues.

2 participants