-
Notifications
You must be signed in to change notification settings - Fork 3
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
[MR-2875] Bulk Downloads 502 Error #1373
Conversation
} | ||
}) | ||
) | ||
} catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😞 I wonder if this is a change we should have everywhere (catch errors, log for cloudwatch, also return some more specific error) . Idk why I didn't notice we weren't try catching our async actions in handlers that should probably be our standard.
Also eslint should warn on this too? Gonna check that out
@@ -2,7 +2,7 @@ | |||
"extends": "../../tsconfig.json", | |||
"compilerOptions": { | |||
"module": "commonjs", | |||
"lib": ["es2021"], | |||
"lib": ["es2021", "DOM"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels... unexpected? What this still needed or is it from previous debugging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The s3 APIs return a ReadableStream which is a browser type. Without this the types from the AWS api were coming back without the right information. In the end we’re not actually using that type, but I think we should keep this so the types stay valid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good I see things working.
Not directly related but just sharing a finding from manual QA - the multi-rate behavior for the "download all rate documents" button just groups everything in the same folder. That surprised me, I was expecting folders or some kind of re-naming in the files to group things a bit more. Not sure if we intentionally designed things that way or just never actively re-designed this feature with multi-rates.
I think we never re-designed it, that’s a good question to bring up for the whole team |
Cool, thanks for writing out that summary! Code looks good and things are working for me as expected in the review app. |
Summary
This PR resolves our issue with bulk downloads not working.
The bug ultimately was due to the way we were invoking the zip archive, triggered by the change to AWS v3 returning a stream instead of a buffer (i’m pretty sure it was a buffer but it definitely was different). I’m still a little confused by this, because we appear to be handling the archive exactly how it’s documented in their examples, but as is it was crashing the bulk download lambda every time.
The zip archive was configured inside of a promise, writing to a stream called
streamPassThrough
. The promise was set to be resolved when that stream emitted theclose
orend
events. After that promise resolved, we passed that stream to s3.PutObject to be uploaded. With the internal AWS v3 change to pass a stream in instead of a buffer, it appears that theclose
andend
events are no longer emitted during the zip process and so I think that the lambda was killed for being promise-locked. I’m still not 100% clear on this because how ever the lambda was dying it was not getting caught by any of ourcatch
clauses. It just died mid stream as far as I could tell. My main fix here was to take the zip out of the promise and just await the s3 upload in the end to sync all the stream processing.The s3.PutObject command was not built to work with streams, when passed an incomplete stream it errored. So I imported the s3.Upload command which is a higher level command built to work with streams. It also can manage tags so that consolidated some of our s3 activity.
Finally, the first thing I did when I was looking at this was trying to straighten out the type of what we were getting back from our initial s3.GetObject calls. This was frustrating and ulitmately fruitless, the type was in fact a Readble which is what we were coercing the return type to anyway. I assumed that since the docs said that s3 was now returning a stream that it would in fact be returning the ReadableStream type to us, and trying to get that type to fit into a Readable which is what the zip archiver wanted was a real pain. Here’s what I learned:
Related issues
https://qmacbis.atlassian.net/browse/MR-2875