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

Prevent 503's on attachment uploads #709

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

toddburnside
Copy link
Contributor

As noted in #528, Heroku has the unfortunate behavior of returning a 503 if you try to send a response before reading the entire body of a request. So, this PR always drains the request stream before responding.

@mergify mergify bot added the service label Sep 12, 2023
@@ -97,6 +98,7 @@ object ObsAttachmentRoutes {
s
.insertAttachment(user, programId, typeTag, fileName, description, req.body)
.flatMap(id => Ok(id.toString))
.guarantee(req.body.compile.drain)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are the unforeseen consequences of always draining the stream regardless of whether it has already been fully or partially read? In some local tests with a 3+M file that was successfully uploaded, a compile.toList where the compile.drain is was reading values of <64K bytes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh this is a really good question. I'm not sure it is well-specified, it may be implementation specific, and I have to take a look.

Are we currently using Blaze server? Do you think we can switch to Ember?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no problem switching to Ember, but I think I remember @tpolecat saying something about Ember vs Blaze so we should check with him.

Copy link
Member

Choose a reason for hiding this comment

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

Ember was broken last time I tried it but you could give it a try. I would like to get off Blaze.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One or more of the Armans have probably fixed it by now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah at this point I'm making any remaining Ember bugs high priority. In the cutting-edge benchmarks its pulled ahead of Blaze.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you want to switch in a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I can work on that. While I do it I will also double-check (and fix if needed) Ember's behavior in this situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could do the switch to ember if you want to look at the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, on my attempt I keep getting these

[ERROR] org.http4s.ember.server.EmberServerBuilderCompanionPlatform - WebSocket connection terminated with exception
java.util.concurrent.TimeoutException: 60 seconds

So I'm probably missing something...

Copy link
Contributor

@cquiroz cquiroz left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -113,6 +115,7 @@ object ObsAttachmentRoutes {
s
.updateAttachment(user, programId, attachmentId, fileName, description, req.body)
.flatMap(_ => Ok())
.guarantee(req.body.compile.drain)
.recoverWith {
case EntityLimiter.EntityTooLarge(_) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I recently fixed a bug in the EntityLimiter middleware but it's not released yet. I'm surprised if it hasn't been affecting you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. It seems to have been working. Of course on Heroku we just got a 503.

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 66.66% and project coverage change: +0.24% 🎉

Comparison is base (52ef2b3) 78.77% compared to head (e1e6cd2) 79.02%.
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #709      +/-   ##
==========================================
+ Coverage   78.77%   79.02%   +0.24%     
==========================================
  Files         507      507              
  Lines        9203     9296      +93     
  Branches       23       28       +5     
==========================================
+ Hits         7250     7346      +96     
+ Misses       1953     1950       -3     
Files Changed Coverage Δ
...dules/service/src/main/scala/lucuma/odb/Main.scala 26.47% <ø> (ø)
...scala/lucuma/odb/graphql/ObsAttachmentRoutes.scala 92.59% <ø> (+0.28%) ⬆️
.../lucuma/odb/graphql/ProposalAttachmentRoutes.scala 90.56% <ø> (+0.36%) ⬆️
...scala/lucuma/odb/service/GmosSequenceService.scala 100.00% <ø> (ø)
...ain/scala/lucuma/odb/service/SequenceService.scala 68.75% <66.66%> (-31.25%) ⬇️

... and 30 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

5 participants