-
Notifications
You must be signed in to change notification settings - Fork 267
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
v3.3.0 regression with multiple listeners #490
Comments
This is the problematic change: edfa360#diff-bfe9874d239014961b1ae4e89875a6155667db834a410aaaa2ebe3cf89820556R172-R173 The cause is that when multiple listeners exist, the code will establish multiple connections in succession, all will be override the value in A naive fix would be to change that logic to this - let result = await sql`listen ${ sql(name) }`
if(channels[name]){
// another listener could have established the channel while we were waiting
channels[name].listeners.push(listener)
result=channels[name].result
} else {
channels[name] = {result, listeners: [listener]}
} However, that's not ideal because we probably need to clean up the multiple Here's a failing test you can add to t('multiple listeners work after a reconnect', async() => {
const sql = postgres(options)
, xs = []
const s1 = await sql.listen('test', x => xs.push('1', x))
const s2 = await sql.listen('test', x => xs.push('2', x))
await sql.notify('test', 'a')
await delay(50)
await sql`select pg_terminate_backend(${ s1.state.pid })`
await delay(50)
await sql.notify('test', 'b')
await delay(50)
sql.end()
return ['1a2a1b2b', xs.join('')]
}) |
Thanks a lot @eugene1g !! I'll get that fixed as soon as I'm back at my comp! |
Released in v3.3.1 |
Hi,
Starting
v3.3.0
, if I have multiple listeners bound to the same event, and the DB connection is interrupted, only the latest listener will successfully reconnect & get triggered for newnotify
events. Additionally, thelistener.state
value is missing for all listeners after the first one. Here's a minimal reproduction that works as expected withv3.2.4
but breaks fromv3.3.0
The text was updated successfully, but these errors were encountered: