fix(server): awaitsendFile
(#5515)
Fixes the intermittent EPIPE errors that myself and others are seeing. By explicitly returning a promise we ensure the caller correctly waits until the `sendFile` is complete before potentially closing or cleaning the socket. This is the most likely bug that would cause EPIPE errors. Fix was confirmed on a live system -- would benefit from a unit test though.
This commit is contained in:
parent
e2d0e944eb
commit
338a028185
1 changed files with 11 additions and 7 deletions
|
@ -336,14 +336,18 @@ export class AssetService {
|
||||||
|
|
||||||
res.set('Cache-Control', 'private, max-age=86400, no-transform');
|
res.set('Cache-Control', 'private, max-age=86400, no-transform');
|
||||||
res.header('Content-Type', mimeTypes.lookup(filepath));
|
res.header('Content-Type', mimeTypes.lookup(filepath));
|
||||||
res.sendFile(filepath, options, (error: Error) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!error) {
|
res.sendFile(filepath, options, (error: Error) => {
|
||||||
return;
|
if (!error) {
|
||||||
}
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (error.message !== 'Request aborted') {
|
if (error.message !== 'Request aborted') {
|
||||||
this.logger.error(`Unable to send file: ${error.name}`, error.stack);
|
this.logger.error(`Unable to send file: ${error.name}`, error.stack);
|
||||||
}
|
}
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue