Skip to content

Error (0, assert_1.default)(s.listenerCount('data') > 0) #366

@younes-zeboudj

Description

@younes-zeboudj

I am getting this error quite frequently:


  (0, assert_1.default)(s.listenerCount('data') > 0)

    at ClientRequest.<anonymous> (C:\Users\DELL\Desktop\project\node_modules\https-proxy-agent\dist\index.js:150:34)
    at Object.onceWrapper (node:events:632:26)
    at ClientRequest.emit (node:events:529:35)
    at tickOnSocket (node:_http_client:841:7)
    at onSocketNT (node:_http_client:904:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

I don't know what could be the reason. The exception is thrown here:

// Some other status code that's not 200... need to re-play the HTTP
        // header "data" events onto the socket once the HTTP machinery is
        // attached so that the node core `http` can parse and handle the
        // error status code.
        // Close the original socket, and a new "fake" socket is returned
        // instead, so that the proxy doesn't get the HTTP request
        // written to it (which may contain `Authorization` headers or other
        // sensitive data).
        //
        // See: https://hackerone.com/reports/541502
        socket.destroy();
        const fakeSocket = new net.Socket({ writable: false });
        fakeSocket.readable = true;
        // Need to wait for the "socket" event to re-play the "data" events.
        req.once('socket', (s) => {
            debug('Replaying proxy buffer for failed request');
            (0, assert_1.default)(s.listenerCount('data') > 0);
            // Replay the "buffered" Buffer onto the fake `socket`, since at
            // this point the HTTP module machinery has been hooked up for
            // the user.
            s.push(buffered);
            s.push(null);
        });
        return fakeSocket;

File : \node_modules\https-proxy-agent\dist\index.js

NOTE:
Earlier than this I got a nodejs warning pointint to the same place:

(node:23488) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 socket listeners added to [ClientRequest]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:591:17)
    at ClientRequest.addListener (node:events:609:10)
    at ClientRequest.once (node:events:653:8)
    at HttpsProxyAgent.connect (C:\Users\DELL\Desktop\project\node_modules\https-proxy-agent\dist\index.js:148:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions