Skip to content

Commit

Permalink
[DI] Guard against invalid probe config and related edge-cases (#4816)
Browse files Browse the repository at this point in the history
  • Loading branch information
watson authored Oct 23, 2024
1 parent 81d6947 commit aff335d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/dd-trace/src/debugger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const log = require('../log')

let worker = null
let configChannel = null
let ackId = 0

const { NODE_OPTIONS, ...env } = process.env

Expand All @@ -24,13 +25,19 @@ function start (config, rc) {
configChannel = new MessageChannel()

rc.setProductHandler('LIVE_DEBUGGING', (action, conf, id, ack) => {
const ackId = `${id}-${conf.version}`
rcAckCallbacks.set(ackId, ack)
rcAckCallbacks.set(++ackId, ack)
rcChannel.port2.postMessage({ action, conf, ackId })
})

rcChannel.port2.on('message', ({ ackId, error }) => {
rcAckCallbacks.get(ackId)(error)
const ack = rcAckCallbacks.get(ackId)
if (ack === undefined) {
// This should never happen, but just in case something changes in the future, we should guard against it
log.error(`Received an unknown ackId: ${ackId}`)
if (error) log.error(error)
return
}
ack(error)
rcAckCallbacks.delete(ackId)
})
rcChannel.port2.on('messageerror', (err) => log.error(err))
Expand Down

0 comments on commit aff335d

Please sign in to comment.