You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally misattributed this problem as #101 where I observed application exiting 0 during reconnects. As it turns out that just happened because Node.js event loop didn't have anything more to do and decided to exit. After adding a setInterval the application stayed up.
The real issue is that after the socket connects the socket may close without openok happening
Here's an illustration with my lovely console.logs
Things happen in the order 1, 2, 3.
4 Never happens
It seems like a doable fix, but I can only think about hacky solutions, maybe you'll be able to figure out a proper solution.
Here's my examples/close.js
After starting this up I just cycle rabbitmq off and on until it happens.
import{setTimeout}from'node:timers/promises';import{AMQPClient}from'../lib/mjs/amqp-client.js'constlog=(...args)=>{conststack=newError().stack.split('\n')constcaller=stack[2].split(' ').pop().match(/(close\.js:\d+:\d+)/)[1]returnconsole.log(newDate().toISOString(), ...args,`-${caller}`);}asyncfunctionloopGetConnection(){letconnectionAttempt=0// eslint-disable-next-line no-constant-conditionwhile(true){log('Trying to connect',++connectionAttempt)try{constamqp=newAMQPClient("amqp://localhost")awaitamqp.connect()console.log('success connect')returnamqp}catch(err){log('Failed to connect')awaitsetTimeout(50)}}}letconn=nullasyncfunctiongetConnection(){if(conn){returnconn}conn=awaitloopGetConnection()conn.logger={debug: (...args)=>log('debug', ...args),info: (...args)=>log('info', ...args),warn: (...args)=>log('warn', ...args),error: (...args)=>log('error', ...args),}conn.onerror=(err)=>{log(err);conn=null;}returnconn;}process.on('exit',(code)=>{log('Process exited')});asyncfunctionrun(){{constconn=awaitgetConnection()constch=awaitconn.channel()awaitch.queue('test',{autoDelete: true})}// eslint-disable-next-line no-constant-conditionwhile(true){constconn=awaitgetConnection()constch=awaitconn.channel()try{awaitch.queue('test',{autoDelete: true})log('Published a message');}catch(err){log('Failed to publish',err)}finally{awaitch.close()}awaitsetTimeout(1000)}}try{awaitrun()log('Run exited normally unexpectedly')}catch(e){log('Run exited unexpectedly',e)}
The text was updated successfully, but these errors were encountered:
Originally misattributed this problem as #101 where I observed application exiting 0 during reconnects. As it turns out that just happened because Node.js event loop didn't have anything more to do and decided to exit. After adding a
setInterval
the application stayed up.The real issue is that after the socket connects the socket may close without
openok
happeningHere's an illustration with my lovely console.logs
Things happen in the order 1, 2, 3.
4 Never happens
It seems like a doable fix, but I can only think about hacky solutions, maybe you'll be able to figure out a proper solution.
Here's my examples/close.js
After starting this up I just cycle rabbitmq off and on until it happens.
The text was updated successfully, but these errors were encountered: