Skip to content

Unexpected error thrown during destorying the socket due to the "servername changed" #3065

@ci010

Description

@ci010

Bug Description

Unexpected error thrown during destorying the socket due to the "servername changed"

Reproducible By

Not quite sure how to simply repro.

I'm also not quite sure why I can trigger this error. I just upgrade the undici version without my code change.

Expected Behavior

The error should be assigned error

Logs & Screenshots

TypeError: The "listener" argument must be of type function. Received undefined
    at checkListener (node:events:267:3)
    at _addListener (node:events:547:3)
    at TLSSocket.addListener (node:events:606:10)
    at TLSSocket.<anonymous> (node:internal/streams/readable:887:35)
    at Object.destroy (C:\Users\CIJhn\Workspace\xmcl-vuetify-refactor\node_modules\.pnpm\undici@6.11.1\node_modules\undici\lib\dispatcher\client-h1.js:759:29)
    at _resume (C:\Users\CIJhn\Workspace\xmcl-vuetify-refactor\node_modules\.pnpm\undici@6.11.1\node_modules\undici\lib\dispatcher\client.js:584:29)
    at resume (C:\Users\CIJhn\Workspace\xmcl-vuetify-refactor\node_modules\.pnpm\undici@6.11.1\node_modules\undici\lib\dispatcher\client.js:529:3)
    at Client7.<computed> (C:\Users\CIJhn\Workspace\xmcl-vuetify-refactor\node_modules\.pnpm\undici@6.11.1\node_modules\undici\lib\dispatcher\client.js:259:31)
    at connect (C:\Users\CIJhn\Workspace\xmcl-vuetify-refactor\node_modules\.pnpm\undici@6.11.1\node_modules\undici\lib\dispatcher\client.js:514:17)

Environment

undici 6.11.1
electron 27.3.9 (node 18.17.1)

Additional context

in node_modules\.pnpm\undici@6.11.1\node_modules\undici\lib\dispatcher\client.js#578

    if (client[kUrl].protocol === 'https:' && client[kServerName] !== request.servername) {
      if (client[kRunning] > 0) {
        return
      }

      client[kServerName] = request.servername
      client[kHTTPContext]?.destroy(new InformationalError('servername changed'))
    }

The

client[kHTTPContext]?.destroy(new InformationalError('servername changed'))

is calling destroy without callback, which will cause error unexpected stack.

But, in node_modules\.pnpm\undici@6.11.1\node_modules\undici\lib\dispatcher\client-h1.js,

    destroy (err, callback) {
      if (closed) {
        queueMicrotask(callback)
      } else {
        socket.destroy(err).on('close', callback)
      }
    },

the destroy requires callback.

I think this can be fixed easily?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions