fix: (UNSURE) ERR_INVALID_STATE
Stream controller in the endpoint that streams files from the S3 bucket would ocassionally crash the server by throwing `TypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed`. This should fix that, but as the conditions that cause it to happen are unknown, this is not certain.
This commit is contained in:
parent
bbc8f090d8
commit
51c7ddce80
@ -12,7 +12,11 @@ export const GET = async ({ params }) => {
|
||||
|
||||
const readableStream = new ReadableStream({
|
||||
start(controller) {
|
||||
stream.on('data', (chunk) => controller.enqueue(chunk));
|
||||
stream.on('data', (chunk) => {
|
||||
if (controller.desiredSize !== null && controller.desiredSize > 0) {
|
||||
controller.enqueue(chunk);
|
||||
}
|
||||
});
|
||||
stream.on('end', () => controller.close());
|
||||
stream.on('error', (err) => controller.error(err));
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user