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

[fix] Can't handle socket hangup (pipe) #1772

Open
3 tasks done
Kelbrad opened this issue Jul 23, 2023 · 0 comments
Open
3 tasks done

[fix] Can't handle socket hangup (pipe) #1772

Kelbrad opened this issue Jul 23, 2023 · 0 comments
Labels

Comments

@Kelbrad
Copy link

Kelbrad commented Jul 23, 2023

Describe the bug

Node.js version: v18.17.0

OS version: Windows (but confirmed on MacOS as well)

Description:

Hi there,

I dont see any way of handling socket errors after initial connection has been established. I'm trying to download a large file with superagent and during download sometimes something happens and connection is broken. I tried to catch that error but it doesn't seem that superagent is notifing about those errors at all.

See code sample:

public static downloadFileToStream(url: string, stream: WriteStream) {
        return new Promise((resolve, reject) => {
            superagent.get(url)
                .on('error', (e) => {
                    logger.error('Req Error!', e);
                    reject(e);
                })
                .pipe(stream)
                .on('error', (e) => {
                    logger.trace('Error!', e);
                    reject(e);
                })
                .on('close', () => {
                    logger.trace('File downloaded!');
                    resolve({});
                })
        });
    }

Actual behavior

If error occurs during connection establishing, is see proper Req Error log messages, but after that, if error occurs during actual data transfer, I dont see anything.

Expected behavior

I would expect to get error event, when error occurs during data transfer.
Afaik this problem may be just related to stream operation (pipe), I havent verified that without using streams

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@Kelbrad Kelbrad added the Bug label Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant