mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:39:37 -05:00 
			
		
		
		
	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
					
				@ -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));
 | 
				
			||||||
 | 
					    return new Promise((resolve, reject) => {
 | 
				
			||||||
      res.sendFile(filepath, options, (error: Error) => {
 | 
					      res.sendFile(filepath, options, (error: Error) => {
 | 
				
			||||||
        if (!error) {
 | 
					        if (!error) {
 | 
				
			||||||
 | 
					          resolve();
 | 
				
			||||||
          return;
 | 
					          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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user