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

connection.cpp: Check return value of write() #5241

Closed
wants to merge 1 commit into from

Conversation

Lotterleben
Copy link

Issue

Resolve one more instance of #1682 .
I manually checked all other instances that

ag '\.write\((.*),(.*)\);' | wc -l
ag '\.read\((.*),(.*)\);' |wc -l

brought up and they were either minor/irrelevant (in examples or tests where this wasn't the focus) or resolved a few lines down (with another if (!result)).

I hope what I did makes sense; if not, I'd of course be happy to improve my PR according to your suggestions.

Tasklist

Requirements / Relations

--

const auto &result = gzip_stream.write(&uncompressed_data[0], uncompressed_data.size());
if (!result)
{
throw util::RuntimeError(
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, while I think it's good to check for error here, I'm not sure that throwing is the right solution - this will kill the server process, as I don't think we have a high-level catch on a per-request basis.

Write errors like this one should cause the client on the other end of the connection to receive an error message, but probably shouldn't cause the osrm-routed process to terminate.

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, while I think it's good to check for error here, I'm not sure that throwing is the right solution - this will kill the server process, as I don't think we have a high-level catch on a per-request basis.

Argh, of course! Sorry about that.

Write errors like this one should cause the client on the other end of the connection to receive an error message, but probably shouldn't cause the osrm-routed process to terminate.

I'm probably missing something, but should the error message really trickle down all the way to the client? If I understand it correctly, compress_buffers() is only trying to apply the compression method set in the HTTP Accept-Encoding header, which, if I understand this description correctly, is more of a suggestion– "if you choose to compress, I understand the following methods". If the server fails to compress, no harm done to the client.

That being said, the compression failure should probably still be logged at the server?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the belated answer, cleaning up the old PRs. ✨

@Lotterleben My reading of that description is the same, though I think we would need to return plaintext if compression fails, right?

So if anyone feels like picking this up again:

  • We need to probably surface to the caller of this function that compression failed (either through the return value or through a custom exception).
  • The call code needs to handle that and return plaintext instead.

@DennisOSRM
Copy link
Collaborator

closing stale PR. Reopen if still relevant.

@DennisOSRM DennisOSRM closed this May 10, 2024
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.

4 participants