express icon indicating copy to clipboard operation
express copied to clipboard

timeout abnormal

Open XiaoTYUT opened this issue 10 months ago • 3 comments

when i use node:18.13.0 and express:4.18.2 to upload file, Uploading will fail between 5 minutes and 6 minutes. Firstly, response will emit "close". Secondly, request will be aborted.

XiaoTYUT avatar Aug 06 '23 05:08 XiaoTYUT

here is my test code

const app = express();

app.post('/_/file/upload/put_file', (req: Request, res: Response) => { const fileStream = req.pipe(fs.createWriteStream('afse'));

fileStream.on('finish', () => {
    res.send('success');
});

fileStream.on('error', (err: Error) => {
    res.status(500).send('failed');
});

req.on('error', (err: Error) => {
    console.log(`${new Date()}   req err  ${err}`);
});

req.on('close', () => {
    console.log(`${new Date()}   req close`);
});

res.on('error', (err: Error) => {
    console.log(`${new Date()}   res err  ${err}`);
});

res.on('close', () => {
    console.log(`${new Date()}   res close`);

}); }); const port = 4000;

app.listen(port, () => { console.log(${port}); });

XiaoTYUT avatar Aug 06 '23 05:08 XiaoTYUT

i try to set request timeout and response timeout , but it is not useful

XiaoTYUT avatar Aug 06 '23 05:08 XiaoTYUT

app.post('/_/file/upload/put_file', (req, res) => {
    const fileStream = fs.createWriteStream('afse');
    
    req.pipe(fileStream);

    fileStream.on('finish', () => {
        res.send('success');
    });

    fileStream.on('error', (err) => {
        console.error(`${new Date()} File stream error: ${err}`);
        res.status(500).send('failed');
    });

    req.on('error', (err) => {
        console.error(`${new Date()} Request error: ${err}`);
    });

    req.on('close', () => {
        console.log(`${new Date()} Request closed`);
        fileStream.destroy();
    });

    res.on('error', (err) => {
        console.error(`${new Date()} Response error: ${err}`);
        fileStream.end();
    });

    res.on('close', () => {
        console.log(`${new Date()} Response closed`);
    });
});

Try this

i think these changes will help and ensure that the file stream is properly closed and that errors are handled more gracefully, reducing the chances of upload failures. if will not work please specifie more info and info. about the content or format. which you trying to upload .

amitmumana avatar Nov 26 '23 13:11 amitmumana