Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access Violation #28773

Closed
jdmota opened this issue Jul 19, 2019 · 3 comments
Closed

Access Violation #28773

jdmota opened this issue Jul 19, 2019 · 3 comments
Assignees
Labels
confirmed-bug Issues with confirmed bugs. worker Issues and PRs related to Worker support.

Comments

@jdmota
Copy link

jdmota commented Jul 19, 2019

  • Version: v12.6.0
  • Platform: Windows 64-bit
  • Subsystem:

It is possible that I'm doing something wrong, but I believe the program should not crash.

By running the following code, the program crashes (most of the time) with C0000005.ACCESS_VIOLATION.

const { Worker } = require( "worker_threads" );

const workerCode = `
const v8 = require( "v8" );
const { parentPort } = require( "worker_threads" );

function share( contents ) {
  const shared = new SharedArrayBuffer( contents.length );
  const buffer = Buffer.from( shared );
  contents.copy( buffer );
  return shared;
}

function serialize( value ) {
  return share( v8.serialize( value ) );
}

parentPort.on( "message", () => {
  parentPort.postMessage( serialize( {} ) );
} );
`;

function createWorker( id ) {
  const child = new Worker( workerCode, {
    eval: true
  } );
  child.postMessage( {} );
  child.on( "message", () => {
    child.terminate();
  } );
  child.on( "error", err => console.error( "error", id, err ) );
  child.once( "exit", () => {
    console.log( "exit", id );
  } );
}

console.log( "5 secs..." );

setTimeout( () => {
  for ( let i = 0; i < 10; i++ ) {
    createWorker( i );
  }
}, 5000 );

I've used procdump64 -e node to produce a dump file (available in the following zip file).
node.exe_190719_222025.zip

Opening the dump file in Visual Studio, shows me this:

image

@Trott Trott added the worker Issues and PRs related to Worker support. label Jul 19, 2019
@rosaxxny

This comment has been minimized.

@addaleax addaleax added the confirmed-bug Issues with confirmed bugs. label Jul 20, 2019
@addaleax addaleax self-assigned this Jul 20, 2019
@addaleax
Copy link
Member

#28788 should address this, thanks for reporting it!

addaleax added a commit to addaleax/node that referenced this issue Jul 21, 2019
Use the parent thread’s `ArrayBuffer::Allocator` when creating a
Worker instance, as that allocator is guaranteed to outlive the
Worker itself.

This requires making the zero-fill flag a thread_local variable
in order to avoid race conditions between different threads.
A test for that behaviour is added as well.

Fixes: nodejs#28777
Fixes: nodejs#28773
@ameriania
Copy link

I found the the same problem,too.

addaleax added a commit to addaleax/node that referenced this issue Aug 17, 2019
Keep a reference to the `ArrayBuffer::Allocator` alive for at least
as long as a `SharedArrayBuffer` allocated by it lives.

Refs: nodejs#28788
Fixes: nodejs#28777
Fixes: nodejs#28773
targos pushed a commit that referenced this issue Aug 20, 2019
Keep a reference to the `ArrayBuffer::Allocator` alive for at least
as long as a `SharedArrayBuffer` allocated by it lives.

Refs: #28788
Fixes: #28777
Fixes: #28773

PR-URL: #29190
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. worker Issues and PRs related to Worker support.
Projects
None yet
5 participants