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

Raise EOF when writing to a closed sandbox over the network #2330

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

pawalt
Copy link
Member

@pawalt pawalt commented Oct 8, 2024

Describe your changes

If Stdin is closed (particularly relevant for sandboxes), and EOF error will be throw instead of accepting the write.

Backward/forward compatibility checks

Check these boxes or delete any item (or this section) if not relevant for this PR.

  • Client+Server: this change is compatible with old servers
  • Client forward compatibility: this change ensures client can accept data intended for later versions of itself

Note on protobuf: protobuf message changes in one place may have impact to
multiple entities (client, server, worker, database). See points above.


Changelog

When writing to a StreamWriter that has already had EOF written, a ValueError is now raised instead of an EOFError.

@pawalt pawalt requested a review from thundergolfer October 8, 2024 10:19
)
except GRPCError as exc:
if exc.status == Status.FAILED_PRECONDITION:
raise EOFError("Stdin is closed. Cannot write to it.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you grab the message in the gRPC exception? It'd be more accurate and forward compatible.
Also not sure EOFError is what a user should expect here, could we instead throw an exception from within the modal.exception namespace that is like 'invalid error'?

Also re-reading the docstring I don't like that it suggests that drain() may always send EOF. It'd be nice to reword that to indicate EOF is only sent once the writer is closed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the comments and switched to ValueError to match python native socket behavior.

Copy link
Contributor

@thundergolfer thundergolfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have some alternative ideas about the appropriate error-handling here, and also think this error-handling functionality is important enough to warrant a basic unit test 👍

@pawalt pawalt force-pushed the pawalt/io_closed branch 2 times, most recently from 69768ac to 6a1fad6 Compare October 14, 2024 20:30
@pawalt
Copy link
Member Author

pawalt commented Oct 14, 2024

@thundergolfer I added a test

Copy link
Contributor

@thundergolfer thundergolfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

)
except GRPCError as exc:
if exc.status == Status.FAILED_PRECONDITION:
raise ValueError("I/O operation on closed file.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would still prefer if the client relied on the message from the server because in the future there could be multiple ways of receiving a FAILED_PRECONDITION.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok ser

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait can I convince you otherwise on this - I want to match the exact error that Python throws on close FDs for close API compatibility, but I don't think it makes sense for the RPC to throw this. I think the separation is valuable here, for the same reason that we don't throw FAILED_PRECONDITION back to the user.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok boss you convinced me

@pawalt pawalt force-pushed the pawalt/io_closed branch 3 times, most recently from 2b35347 to b846ece Compare October 15, 2024 21:25
@pawalt
Copy link
Member Author

pawalt commented Oct 15, 2024

@prbot automerge

Copy link

@modal-pr-review-automation modal-pr-review-automation bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some required workflows are pending. Will automerge once they complete successfully. Please bear with us in this difficult time.

Copy link

@modal-pr-review-automation modal-pr-review-automation bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot automerge PR because workflow 'CI / CD' failed.

@pawalt pawalt merged commit 6fed77c into main Oct 16, 2024
21 checks passed
@pawalt pawalt deleted the pawalt/io_closed branch October 16, 2024 18:21
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