Skip to content

Javascript engine starts scripts multiple times on changes with script mirroring feature enabled #598

Closed

Description

@MiGoller

Hey all,

I've setup ioBroker on an Intel Atom Z8350 and Ubuntu 18.04 LTS using the script installer. The setup worked fine, but I had to switch from the js2fs adapter to the script mirroring feature of the Javascript adapter because of the known soef issues.

The javascript adapter works well but I encounter an issue that modified scripts get started multiple times. This is the scenario:

  • I create and modify scripts with Microsoft Visual Studio Code.
  • It doesn't matter if I modify the script file on the Linux file system or on the exposed Samba file share. Copying based on ssh or scp triggers the same behavior.
  • I can easily reproduce the issue with the simple test-script.
  • If I modify a script after the adapter has been started or restarted, everything works as expected: The adapter stops the modified script and restarts the script.
  • If I modify the same or another script again, the adapter will start the modified script multiple times, but at least two times.
  • After an amount of time, I don't know how much time exactly, the adapter works as expected again and modified scripts get started only once. The next modification will trigger the issue again.

This is the test-script script.js.Skript1 for reproducing the issue.

///

let counter = 0;

function main() {
    // Test 07.06.2020
    //  Javascript-adapter
    counter += 1;
    log(`Skript startet: ${counter}`,"error");
}

main();

These are the debug-log entries for the first modification of the script after starting or restarting the adpater:

javascript.0	2020-06-07 11:01:28.809	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:01:27.138	info	(22075) script.js.Skript1: registered 0 subscriptions and 0 schedules
javascript.0	2020-06-07 11:01:27.138	error	(22075) script.js.Skript1: Skript startet: 1
javascript.0	2020-06-07 11:01:27.105	info	(22075) Start javascript script.js.Skript1
javascript.0	2020-06-07 11:01:27.092	info	(22075) Stop script script.js.Skript1
javascript.0	2020-06-07 11:01:27.074	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:01:27.073	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:01:27.069	debug	(22075) Update script script.js.Skript1 in DB
javascript.0	2020-06-07 11:01:27.064	debug	(22075) File /opt/iobroker/scripts/Skript1.js change

If I change the script once again without restarting the adapter the adapter will start the script at least two times:

javascript.0	2020-06-07 11:02:56.734	info	(22075) script.js.Skript1: registered 0 subscriptions and 0 schedules
javascript.0	2020-06-07 11:02:56.734	error	(22075) script.js.Skript1: Skript startet: 1
javascript.0	2020-06-07 11:02:56.704	info	(22075) Start javascript script.js.Skript1
javascript.0	2020-06-07 11:02:56.698	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:02:56.680	info	(22075) script.js.Skript1: registered 0 subscriptions and 0 schedules
javascript.0	2020-06-07 11:02:56.680	error	(22075) script.js.Skript1: Skript startet: 1
javascript.0	2020-06-07 11:02:56.662	info	(22075) Start javascript script.js.Skript1
javascript.0	2020-06-07 11:02:56.656	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:02:56.651	info	(22075) Stop script script.js.Skript1
javascript.0	2020-06-07 11:02:56.646	debug	(22075) Update /opt/iobroker/scripts/Skript1.js on disk
javascript.0	2020-06-07 11:02:56.639	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:02:56.637	info	(22075) Stop script script.js.Skript1
javascript.0	2020-06-07 11:02:56.630	debug	(22075) Update /opt/iobroker/scripts/Skript1.js on disk
javascript.0	2020-06-07 11:02:56.618	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:02:56.617	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:02:56.610	debug	(22075) Update script script.js.Skript1 in DB
javascript.0	2020-06-07 11:02:56.608	debug	(22075) File /opt/iobroker/scripts/Skript1.js change
javascript.0	2020-06-07 11:02:56.604	debug	(22075) Update script script.js.Skript1 in DB
javascript.0	2020-06-07 11:02:56.601	debug	(22075) File /opt/iobroker/scripts/Skript1.js change

Please let me know if you need further information or if I can assist anymore.

KR, MiGoller

Activity

  1. Apollon77 commented on Jul 26, 2020

    @Apollon77
    Contributor

    Bitte in Javascript 4.6.19 versuchen

  2. MiGoller commented on Jul 28, 2020

    @MiGoller
    Author

    Hallo @Apollon77 .

    Vielen Dank. Sieht gut aus in den Versionen 4.6.19 und auch 4.6.20: Skripte werden bislang nur einmalig bei Änderungen gestartet.
    Allerdings bin ich soeben auf folgende Fehlermeldungen gestoßen, nachdem ich direkt von einem Windows Client auf die SMB-Freigabe zu ioBroker zugegriffen habe.

    2020-07-29 00:31:05.479 - error: javascript.0 (28773) uncaught exception: ENOENT: no such file or directory, scandir '/opt/iobroker/scripts/.tmp/'
    --
    2020-07-29 00:31:05.480 - error: javascript.0 (28773) Error: ENOENT: no such file or directory, scandir '/opt/iobroker/scripts/.tmp/'
    at Object.readdirSync (fs.js:948:3)
    at Mirror.watchFolders (/opt/iobroker/node_modules/iobroker.javascript/lib/mirror.js:63:26)
    at Mirror.onFileChange (/opt/iobroker/node_modules/iobroker.javascript/lib/mirror.js:328:55)
    at FSWatcher. (/opt/iobroker/node_modules/iobroker.javascript/lib/mirror.js:74:22)
    at FSWatcher.emit (events.js:315:20)
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:135:12)
    

    Ein Verzeichnis .tmp gibt es in dem Verzeichnis /opt/iobroker/scripts auch eben nicht. Anscheinend reagiert der FS-Watcher aber auf eine Veränderung eben dieses Verzeichnisses, was zu einem Neustart des Adapters geführt hat. Ich werde das weiter beobachten und dann Feedback geben.

    Danke und viele Grüße,
    MiGoller

  3. Apollon77 commented on Jul 28, 2020

    @Apollon77
    Contributor

    Den Fehler kann ich morgen mal noch anfangen. Das .tmp kann vllt von bestimmten file Aktionen kommen.

  4. MiGoller commented on Jul 28, 2020

    @MiGoller
    Author

    Alles klar. Ich hatte auch schon meine smb.conf überprüft, ob ich da irgendwelche Sonderlocken konfiguriert hatte. Das brachte allerdings auch keine Erkenntnisse.

  5. Apollon77 commented on Jul 30, 2020

    @Apollon77
    Contributor

    4.6.22 fixt das ... wird geloggt, muss man mal beonachten (Sag al hast Du Sentry deaktiviert oder nen js.controller <3? ... den Fehler hatte ich garnicht im Sentry bekommen)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions