Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. English
  3. Scripting / Logic
  4. JavaScript
  5. setTimeout() keeps running on script stop.

NEWS

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    22
    1
    1.1k

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    9.1k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    14
    1
    2.4k

setTimeout() keeps running on script stop.

Geplant Angeheftet Gesperrt Verschoben JavaScript
4 Beiträge 3 Kommentatoren 1.1k Aufrufe 2 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • J Offline
    J Offline
    j1s2e3
    schrieb am zuletzt editiert von
    #1

    I have a js-script which sends every 20min the setpoint temperatures to the heating control panels.
    Something likes this:

    let heatingCbTmo = null;
    function heatingCb() {
        // do something and send setpoint temps
        // resart timeout
        heatingCbTmo = setTimeout(heatingCb, 20 * 60 * 1000);
    
    }
    function main() {
        // setup
        heatingCb();
    }
    main();
    

    The problem is, that the timeout keeps running although I have stopped it. If I start the script again (or do an restart), then I have multiple timeout callbacks running! This annoying and not what you expect if you terminate the script. Currently I have 3 timeout instances running.

    Is this a desired behavior, or a bug? If it's not a bug, how can I cancel (with cancelTimeout(id)) the timeout on script stop/exit or restart? I need somehow a hook to call cancelTimeout(heatingCbTmo) on exit/stop/restart.

    Platform: rapsi4, raspbian (up to date)
    Node.js: v16.19.0
    NPM: 8.19.3
    pi@iobroker:~ $ iob update
    Used repository: beta
    Adapter "admin" : 6.3.6 , installed 6.3.6
    Adapter "backitup" : 2.5.12 , installed 2.5.12
    Adapter "discovery" : 3.1.0 , installed 3.1.0
    Adapter "enocean" : 0.8.4 , installed 0.8.4
    Adapter "homeconnect" : 1.1.1 , installed 1.1.1
    Adapter "influxdb" : 3.2.0 , installed 3.2.0
    Adapter "jarvis" : 3.1.2 , installed 3.1.2
    Adapter "javascript" : 6.1.4 , installed 6.1.4
    Controller "js-controller": 4.0.24 , installed 4.0.24
    Adapter "rpi2" : 1.3.2 , installed 1.3.2
    Adapter "simple-api" : 2.7.2 , installed 2.7.2
    Adapter "socketio" : 6.3.3 , installed 6.3.3
    Adapter "telegram" : 1.15.2 , installed 1.15.2
    Adapter "web" : 5.4.3 , installed 5.4.3
    Adapter "ws" : 2.3.5 , installed 2.3.5

    mickymM 1 Antwort Letzte Antwort
    0
    • J j1s2e3

      I have a js-script which sends every 20min the setpoint temperatures to the heating control panels.
      Something likes this:

      let heatingCbTmo = null;
      function heatingCb() {
          // do something and send setpoint temps
          // resart timeout
          heatingCbTmo = setTimeout(heatingCb, 20 * 60 * 1000);
      
      }
      function main() {
          // setup
          heatingCb();
      }
      main();
      

      The problem is, that the timeout keeps running although I have stopped it. If I start the script again (or do an restart), then I have multiple timeout callbacks running! This annoying and not what you expect if you terminate the script. Currently I have 3 timeout instances running.

      Is this a desired behavior, or a bug? If it's not a bug, how can I cancel (with cancelTimeout(id)) the timeout on script stop/exit or restart? I need somehow a hook to call cancelTimeout(heatingCbTmo) on exit/stop/restart.

      Platform: rapsi4, raspbian (up to date)
      Node.js: v16.19.0
      NPM: 8.19.3
      pi@iobroker:~ $ iob update
      Used repository: beta
      Adapter "admin" : 6.3.6 , installed 6.3.6
      Adapter "backitup" : 2.5.12 , installed 2.5.12
      Adapter "discovery" : 3.1.0 , installed 3.1.0
      Adapter "enocean" : 0.8.4 , installed 0.8.4
      Adapter "homeconnect" : 1.1.1 , installed 1.1.1
      Adapter "influxdb" : 3.2.0 , installed 3.2.0
      Adapter "jarvis" : 3.1.2 , installed 3.1.2
      Adapter "javascript" : 6.1.4 , installed 6.1.4
      Controller "js-controller": 4.0.24 , installed 4.0.24
      Adapter "rpi2" : 1.3.2 , installed 1.3.2
      Adapter "simple-api" : 2.7.2 , installed 2.7.2
      Adapter "socketio" : 6.3.3 , installed 6.3.3
      Adapter "telegram" : 1.15.2 , installed 1.15.2
      Adapter "web" : 5.4.3 , installed 5.4.3
      Adapter "ws" : 2.3.5 , installed 2.3.5

      mickymM Online
      mickymM Online
      mickym
      Most Active
      schrieb am zuletzt editiert von mickym
      #2

      @j1s2e3 I guess cancelling Timeout ist with

      clearTimeout(myTimeout);
      

      not cancelTimeout.

      I`m not sure that if you start the script again a new instance is created and you get not the same instance as the timeout was created before. But as i do not work with JS - may someone else can help.

      Jeder Flow bzw. jedes Script, das ich hier poste implementiert jeder auf eigene Gefahr. Flows und Scripts können Fehler aufweisen und weder der Seitenbetreiber noch ich persönlich können hierfür haftbar gemacht werden. Das gleiche gilt für Empfehlungen aller Art.

      J 1 Antwort Letzte Antwort
      0
      • mickymM mickym

        @j1s2e3 I guess cancelling Timeout ist with

        clearTimeout(myTimeout);
        

        not cancelTimeout.

        I`m not sure that if you start the script again a new instance is created and you get not the same instance as the timeout was created before. But as i do not work with JS - may someone else can help.

        J Offline
        J Offline
        j1s2e3
        schrieb am zuletzt editiert von
        #3

        @mickym Yes, you are right. It was my fault while writing. In the code I had it correct:

                if (heatingCbTmo != null) {
                    clearTimeout(heatingCbTmo);
                    heatingCbTmo = null;
                }
        

        ... and it's working (in subcribe for instance). But the problem is stopping the script. On stop I get this log:

        ...
        12:36:15.857	info	javascript.0 (619) script.js.common.VirtualAutomations.04_Heizung: ### setting: room=14-gwc temp=16
        12:43:21.268	info	javascript.0 (619) Stop script script.js.common.VirtualAutomations.04_Heizung
        12:56:13.005	info	javascript.0 (619) script.js.common.VirtualAutomations.04_Heizung: ###### before temp_override=0
        12:56:13.006	info	javascript.0 (619) script.js.common.VirtualAutomations.04_Heizung: ### setting: room=01-die temp=20
        ...
        

        so I thought it's not running anymore, including timeouts. But it seems the timeout keeps running...

        Now I'm searching for a way to place a hook on or before exit to cancel the timeout with clearTimeout(). No idea so far...

        process.on("beforeExit", (code) => {});
        

        process.on does not work. It's not defined.

        The first question is, if timeout should keep running if the sarting script is stopped? Whether it's a bug or a feature.

        paul53P 1 Antwort Letzte Antwort
        0
        • J j1s2e3

          @mickym Yes, you are right. It was my fault while writing. In the code I had it correct:

                  if (heatingCbTmo != null) {
                      clearTimeout(heatingCbTmo);
                      heatingCbTmo = null;
                  }
          

          ... and it's working (in subcribe for instance). But the problem is stopping the script. On stop I get this log:

          ...
          12:36:15.857	info	javascript.0 (619) script.js.common.VirtualAutomations.04_Heizung: ### setting: room=14-gwc temp=16
          12:43:21.268	info	javascript.0 (619) Stop script script.js.common.VirtualAutomations.04_Heizung
          12:56:13.005	info	javascript.0 (619) script.js.common.VirtualAutomations.04_Heizung: ###### before temp_override=0
          12:56:13.006	info	javascript.0 (619) script.js.common.VirtualAutomations.04_Heizung: ### setting: room=01-die temp=20
          ...
          

          so I thought it's not running anymore, including timeouts. But it seems the timeout keeps running...

          Now I'm searching for a way to place a hook on or before exit to cancel the timeout with clearTimeout(). No idea so far...

          process.on("beforeExit", (code) => {});
          

          process.on does not work. It's not defined.

          The first question is, if timeout should keep running if the sarting script is stopped? Whether it's a bug or a feature.

          paul53P Offline
          paul53P Offline
          paul53
          schrieb am zuletzt editiert von
          #4

          @j1s2e3 sagte: The first question is, if timeout should keep running if the sarting script is stopped? Whether it's a bug or a feature.

          It's a bug in your javascript instance. Restart the instance or ioBroker.

          Bitte verzichtet auf Chat-Nachrichten, denn die Handhabung ist grauenhaft !
          Produktiv: RPi 2 mit S.USV, HM-MOD-RPI und SLC-USB-Stick mit root fs

          1 Antwort Letzte Antwort
          0
          Antworten
          • In einem neuen Thema antworten
          Anmelden zum Antworten
          • Älteste zuerst
          • Neuste zuerst
          • Meiste Stimmen


          Support us

          ioBroker
          Community Adapters
          Donate

          805

          Online

          32.5k

          Benutzer

          81.6k

          Themen

          1.3m

          Beiträge
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
          ioBroker Community 2014-2025
          logo
          • Anmelden

          • Du hast noch kein Konto? Registrieren

          • Anmelden oder registrieren, um zu suchen
          • Erster Beitrag
            Letzter Beitrag
          0
          • Home
          • Aktuell
          • Tags
          • Ungelesen 0
          • Kategorien
          • Unreplied
          • Beliebt
          • GitHub
          • Docu
          • Hilfe