Skip to content

fix: improve script restart behavior for multi-instance setups#2194

Merged
GermanBluefox merged 2 commits intoioBroker:masterfrom
Eistee82:feat/script-restart-fixes
Apr 11, 2026
Merged

fix: improve script restart behavior for multi-instance setups#2194
GermanBluefox merged 2 commits intoioBroker:masterfrom
Eistee82:feat/script-restart-fixes

Conversation

@Eistee82
Copy link
Copy Markdown
Contributor

Summary

Fixes two issues that occur when running multiple JavaScript adapter instances:

Problem 1: Duplicate "Stopping script" log messages
When stopScript() was called for a script that was not running on the current instance, it would still log Stopping script and attempt to set the scriptEnabled state — even though there was nothing to stop. This caused confusing duplicate log entries.

Fix: Added an early return in stopScript() that checks this.scripts[name] before proceeding. If the script is not loaded on this instance, it returns false immediately without logging or side effects.

Problem 2: Unnecessary script restarts on unrelated instances
When a script's source code was changed (e.g., saved in the editor), the onObjectChange handler would trigger a stop/restart cycle on every JavaScript adapter instance — not just the one that owns the script. This led to unnecessary restart attempts and confusing log output on instances that don't run the script.

Fix: Changed the unconditional else branch in onObjectChange to an else if that checks whether the script's engine (current or former) matches system.adapter.${this.namespace}. Only the owning instance now reacts to source changes.

Changes

  • src/main.ts: Early return in stopScript() when script is not running
  • src/main.ts: Instance-scoped restart in onObjectChange for script source changes
  • build/main.js: Compiled output matching the source changes
  • README.md: Changelog entries under WORK IN PROGRESS

Test plan

  • Start two JavaScript adapter instances (e.g., javascript.0 and javascript.1)
  • Assign a script to javascript.0, save/edit it
  • Verify only javascript.0 logs "Stopping script" / restart — javascript.1 stays silent
  • Disable a script and verify no duplicate "Stopping" messages appear
  • npm run test passes (41 integration tests)
  • npm run lint passes on src/main.ts

🤖 Generated with Claude Code

Eistee82 and others added 2 commits April 10, 2026 22:37
Prevents duplicate 'Stopping script' logs by early-returning when script
is not running. Restricts restart handling to the owning instance only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GermanBluefox GermanBluefox enabled auto-merge (squash) April 11, 2026 10:05
Copy link
Copy Markdown
Contributor

@GermanBluefox GermanBluefox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! lgtm

@GermanBluefox GermanBluefox merged commit 2a8ff4c into ioBroker:master Apr 11, 2026
17 checks passed
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.

2 participants