Skip to content
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

timeout abnormal #5238

Open
XiaoTYUT opened this issue Aug 6, 2023 · 3 comments
Open

timeout abnormal #5238

XiaoTYUT opened this issue Aug 6, 2023 · 3 comments

Comments

@XiaoTYUT
Copy link

XiaoTYUT commented Aug 6, 2023

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
Copy link
Author

XiaoTYUT commented Aug 6, 2023

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 XiaoTYUT changed the title timeout abnormal timeout abnormal Aug 6, 2023
@XiaoTYUT
Copy link
Author

XiaoTYUT commented Aug 6, 2023

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

@amitmumana
Copy link

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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants