Skip to content

Avoid problems when required twice - #76

Closed
vbfox wants to merge 1 commit into
TooTallNate:masterfrom
vbfox:required_twice
Closed

vbfox wants to merge 1 commit into
TooTallNate:masterfrom
vbfox:required_twice

Conversation

@vbfox

@vbfox vbfox commented Apr 27, 2017

Copy link
Copy Markdown

It's possible due to test runners like jest playing with the node runtime object.

The native module can't be required twice but the javascript one can. As the javascript one return a mutated version of the native one it create problems :

exports._writePointer = exports.writePointer

exports.writePointer = function writePointer (buf, offset, ptr) {
  debug('writing pointer to buffer', buf, offset, ptr)
  exports._writePointer(buf, offset, ptr)
  exports._attach(buf, ptr)
}

After 2+ executions of this code writePointer would call itself and produce a stack overflow exception.

Additional info

Possible due to test runners like jest playing with the node runtime
object.
@vbfox vbfox closed this Sep 11, 2017
sa-MatteoHausner added a commit to sa-MatteoHausner/ref that referenced this pull request May 29, 2019
prevent infinite recursions
sa-MatteoHausner added a commit to sa-MatteoHausner/ref that referenced this pull request Oct 28, 2019
prevent infinite recursions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant