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

closeClient does not work, but exists in the type #176

Closed
2 tasks done
starnayuta opened this issue Apr 4, 2023 · 2 comments
Closed
2 tasks done

closeClient does not work, but exists in the type #176

starnayuta opened this issue Apr 4, 2023 · 2 comments
Labels
feature request New feature to be added good first issue Good for newcomers

Comments

@starnayuta
Copy link
Contributor

starnayuta commented Apr 4, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

^4.0.0

Plugin version

^6.0.0

Node.js version

18.14.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

13.3

Description

Since 6.0.0 closeClient does not work, but it continues to exist in index.d.ts.

#147

Steps to Reproduce

The test times out if the client is not manually closed, even if closeClient is enabled.

test('custom ioredis client that is already connected', (t) => {
  t.plan(9)
  const fastify = Fastify()
  const Redis = require('ioredis')
  const redis = new Redis({ host: 'localhost', port: 6379 })

  // use the client now, so that it is connected and ready
  redis.set('key', 'value', (err) => {
    t.error(err)
    redis.get('key', (err, val) => {
      t.error(err)
      t.equal(val, 'value')

      fastify.register(fastifyRedis, {
        client: redis,
        lazyConnect: false,
        closeClient: true
      })

      fastify.ready((err) => {
        t.error(err)
        t.equal(fastify.redis, redis)

        fastify.redis.set('key2', 'value2', (err) => {
          t.error(err)
          fastify.redis.get('key2', (err, val) => {
            t.error(err)
            t.equal(val, 'value2')

            fastify.close(function (err) {
              t.error(err)
              // fastify.redis.quit(function (err) {
              //   t.error(err)
              // })
            })
          })
        })
      })
    })
  })
})

Expected Behavior

  1. fix closeClient to work
  2. remove the closeClient type definition ( = client must be closed manually).

I prefer 1.

Please tell me which solution to take, and I will send PR.

@mcollina
Copy link
Member

This works as documented in the README: if the client is set, you are on your own.

A PR to change this behavior would be awesome.

@mcollina mcollina added good first issue Good for newcomers feature request New feature to be added labels Apr 10, 2023
@starnayuta starnayuta mentioned this issue Apr 10, 2023
4 tasks
@starnayuta
Copy link
Contributor Author

The fix was released in v6.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature to be added good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants