Skip to content

Commit

Permalink
Merge pull request newrelic#1186 from NodeJS-agent/nwolfe/protect-create
Browse files Browse the repository at this point in the history
NODE-1493 Check segment validity
  • Loading branch information
Bryan Clement committed Jun 29, 2017
2 parents 2b977c2 + ea24465 commit cb510b3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/shim/message-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ function _makeConsumeSegment(shim, msgDesc, checkCAT) {

// Create the segment and attach any CAT data.
var segment = shim.createSegment(segDesc)
if (checkCAT && msgDesc.messageProperties) {
if (checkCAT && segment && msgDesc.messageProperties) {
shim.handleCATHeaders(msgDesc.messageProperties, segment)
}

Expand Down
3 changes: 2 additions & 1 deletion lib/shim/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ function _bindStream(shim, stream, segment, spec) {
// Wrap emit such that each event handler is executed within context of this
// segment or the event-specific segment.
shim.wrap(stream, 'emit', function wrapStreamEmit(shim, emit) {
var tx = segment.transaction
var streamBoundEmit = shim.bindSegment(emit, segment, true)
var eventSegment = null
var eventBoundEmit = null
Expand All @@ -1931,7 +1932,7 @@ function _bindStream(shim, stream, segment, spec) {

return function wrappedEmit(evnt) {
var emitToCall = streamBoundEmit
if (evnt === specEvent) {
if (evnt === specEvent && tx.isActive()) {
if (!eventBoundEmit) {
eventSegment = shim.createSegment(segmentName, segment)
eventBoundEmit = shim.bindSegment(emit, eventSegment, true)
Expand Down

0 comments on commit cb510b3

Please sign in to comment.