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
There's an issue causing removeListeners to not remove all the order callbacks that were registered in registerListeners causing a leak, as new orders accumulate this greatly affects performance eventually killing he process
Issue Breakdown
Upon initial creation of an order with cid the cbGID will be undefined.{cid} since gid was never provided
Calling registerListeners will register the mentioned cbGID which later is used with removeListeners
Submitting the order will invoke an update message updating the gid to null (we listen to update to verify the order was successfully submitted
cbGID will now be null.{cid} mismatching the initial cbGID, rendering removeListeners useless which will increase callbacks size infinitely - this specifically affects systems automatically creating orders.
const{ Order }=require('bfx-api-node-models')constws= ... // setup WSv2 instance for order updates/submission// Build new orderconsto=newOrder({cid: Date.now(),symbol: 'tBTCUSD',price: 7000.0,amount: -0.02,type: Order.type.EXCHANGE_LIMIT},ws)// note WSv2 client passed in hereletclosed=false// Enable automatic updateso.registerListeners()o.on('update',()=>{debug('order updated: %j',o.serialize())o.removeListeners()// ISSUE - `cbGID` is not the same as before the `update`})o.on('close',()=>{debug('order closed: %s',o.status)closed=trueo.removeListeners()// Probably also problematic})debug('submitting order %d',o.cid)o.submit().then(()=>{debug('got submit confirmation for order %d [%d]',o.cid,o.id)}).catch((err)=>{debug('failed to submit order: %s',err.message)})
The text was updated successfully, but these errors were encountered:
Summary
There's an issue causing
removeListeners
to not remove all the order callbacks that were registered inregisterListeners
causing a leak, as new orders accumulate this greatly affects performance eventually killing he processIssue Breakdown
cid
thecbGID
will beundefined.{cid}
sincegid
was never providedregisterListeners
will register the mentionedcbGID
which later is used withremoveListeners
update
message updating thegid
tonull
(we listen toupdate
to verify the order was successfully submittedcbGID
will now benull.{cid}
mismatching the initialcbGID
, renderingremoveListeners
useless which will increase callbacks size infinitely - this specifically affects systems automatically creating orders.Sample code
(I took the sample code from https://github.com/bitfinexcom/bfx-api-node-models/#order marking where the issue is prominent)
The text was updated successfully, but these errors were encountered: