nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

NW.JS 0.67.0 Context Issues

Open ddreharov opened this issue 1 year ago • 3 comments

Issue Type

Similar to this https://github.com/nwjs/nw.js/issues/7901 I'm experiencing the same error in Node Context as well. The issue could not be reproduced in version 0.60.0 or version 0.57.1.

Another thing to add is that when wrapping the timer function calls in try-catch blocks everything works as expected and there are no issues or errors thrown. Unfortunately this solution doesn't work for me.

I suspect that there are changes in managing the context in different situations.

  • [x] Bug Report
  • [ ] Feature Request
  • [x] Successfully reproduced against the latest version of NW.js?

Current/Missing Behavior

Uncaught TypeError: setInterval(...).unref is not a function Uncaught TypeError: setTimeout(...).unref is not a function

Expected/Proposed Behavior

setInterval().unref() and setTimeout().unref() to work

Additional Info

  • Operating System: Linux
  • NW.js Version: 0.67.0 , 0.66.1
  • Repro Link:
  • Code snippet:

package.json

{
  "name": "test",
  "main": "index.js"
}

or

{
  "name": "test",
  "main": "index.html"
}

index.js

process.stdout.write('+++++++++++ INDEX INIT')
require('./timers');
process.stdout.write('+++++++++++ INDEX EOF')

timers.js

process.stdout.write('TIMERS INITIALIZE\n')
function testSetTimeout() {
  const timer = setTimeout(() => {
    process.stdout.write('SET TIMEOUT COMPLETED\n')
  }, 1000).unref();
}

function testSetInterval() {
  const timer = setInterval(() => {
    process.stdout.write('SET INTERVAL EXEC\n')
  }, 1000).unref();
}

testSetTimeout();
testSetInterval();

process.stdout.write('+++++++++++ EOF\n')

index.html

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <script>
      process.stdout.write('+++++++++++ HELLO FROM INDEX\n')
      const timers = require('./timers')
    </script>
  </body>
</html>
  • Crash report: Uncaught TypeError: setInterval(...).unref is not a function Uncaught TypeError: setTimeout(...).unref is not a function

ddreharov avatar Aug 09 '22 08:08 ddreharov

A couple more things to add:

If used only in Node Ctx with the code above we'll see the following output:

+++++++++++ INDEX INIT
TIMERS INITIALIZE
SET TIMEOUT COMPLETED

and the application will freeze.

So basically what happened is that first timer function testSetTimeout worked correctly and then the function testSetInterval did not.

If I wrap the first timer function in try-catch block both timers are working but an error is thrown from the first one. Weird..

From my report above I've said that there were no errors thrown because I was trying to log the error from the try-catch block which is undefined.

@ayushmxn I saw you're active on this repo lately can you share your advice / opinion about this?

cc: @rogerwang

ddreharov avatar Aug 10 '22 06:08 ddreharov

hi @ddreharov been a bit busy lately, i'll try to look at this by this Sunday

ayushmanchhabra avatar Aug 13 '22 22:08 ayushmanchhabra

@ayushmxn hey, have you managed to check it out?

ddreharov avatar Sep 12 '22 10:09 ddreharov