Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@David-van-der-Sluijs
Copy link
Contributor

Replace function declaration with arrow function to properly reference the session object when closing timed-out HTTP/2 sessions.

I would sometimes get this error in my web application with fastify v5.5.0:

172444 |   const httpsOptions = options.https === true ? {} : options.https
172445 |
172446 |   if (options.http2) {
172447 |     const server = typeof httpsOptions === 'object' ? http2.createSecureServer(httpsOptions, httpHandler) : http2.createServer(options.http, httpHandler)
172448 |     server.on('session', (session) => session.setTimeout(options.http2SessionTimeout, function closeSession () {
172449 |       this.close()
                    ^
TypeError: this.close is not a function. (In 'this.close()', 'this.close' is undefined)

Replace function declaration with arrow function to properly reference
the session object when closing timed-out HTTP/2 sessions.

Signed-off-by: David van der Sluijs <[email protected]>
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 4e5a363 into fastify:main Sep 22, 2025
30 checks passed
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

Successfully merging this pull request may close these issues.

4 participants