Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

Fail to understand how I should handle connection failures from a client. #184

@akc42

Description

@akc42

I am trying to construct a client that will handle failure conditions correctly. I am currently testing a situation where the client tries to connect to a server that is not running. I can see at the socket level a tls.connect is failing with "Connection Refused", but this doesn't seem to be translating into anything I can use.

Here is a promise I am trying to create for the session

      this.sessionPromise = new Promise((resolve,reject) => {
        function onSessionError(err) {
          session.removeListener('error', onSessionError);
          reject(err);
        }
        const session = http2.connect(
          `https://localhost:${process.env.PAS_HTTPS_PORT}`,
          { rejectUnauthorized: false},
          () => {
            session.removeListener('error', onSessionError);
            resolve(session);
          }
        );
        session.on('error', onSessionError);
      });

but that promise never resolves.

In a previous attempt, I didn't wait for the connection to establish, and after creating the connection immediately created a request - something like this

const session = http2.connect(
          `https://localhost:${process.env.PAS_HTTPS_PORT}`,
          { rejectUnauthorized: false}
);
const req = session.request(headers)
req.on('error', /*did something here */)
req.on('end', /* did something here */)

In that scenario, the 'end' event was raised pretty quickly - but no error.event. Unfortunately that makes it very difficult to understand why the 'end' event was raised, so I didn't pursue it.

What is the correct way of dealing with this? docs don't give much clue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions