Browse Source

fix: optimize plugin last active time tracking in stdio handler (#59)

* fix: optimize plugin last active time tracking in stdio handler

Move last active time update to occur on each data receipt to ensure more accurate tracking of plugin activity

* feat: enhance plugin activity monitoring and logging

Improve plugin activity tracking by:
- Extending inactivity timeout to 120 seconds before considering a plugin dead
- Adding warning log for plugins inactive for more than 60 seconds
- Including plugin identifier in log messages for better traceability
Yeuoly 4 months ago
parent
commit
e0672c3c1a
1 changed files with 15 additions and 2 deletions
  1. 15 2
      internal/core/plugin_manager/local_runtime/stdio_handle.go

+ 15 - 2
internal/core/plugin_manager/local_runtime/stdio_handle.go

@@ -90,6 +90,9 @@ func (s *stdioHolder) StartStdout(notify_heartbeat func()) {
 			continue
 		}
 
+		// update the last active time on each time the plugin sends data
+		s.lastActiveAt = time.Now()
+
 		plugin_entities.ParsePluginUniversalEvent(
 			data,
 			"",
@@ -106,7 +109,6 @@ func (s *stdioHolder) StartStdout(notify_heartbeat func()) {
 				}
 			},
 			func() {
-				s.lastActiveAt = time.Now()
 				// notify launched
 				notify_heartbeat()
 			},
@@ -185,9 +187,20 @@ func (s *stdioHolder) Wait() error {
 		select {
 		case <-ticker.C:
 			// check heartbeat
-			if time.Since(s.lastActiveAt) > 60*time.Second {
+			if time.Since(s.lastActiveAt) > 120*time.Second {
+				log.Error(
+					"plugin %s is not active for 120 seconds, it may be dead, killing and restarting it",
+					s.pluginUniqueIdentifier,
+				)
 				return plugin_errors.ErrPluginNotActive
 			}
+			if time.Since(s.lastActiveAt) > 60*time.Second {
+				log.Warn(
+					"plugin %s is not active for %d seconds, it may be dead",
+					s.pluginUniqueIdentifier,
+					time.Since(s.lastActiveAt).Seconds(),
+				)
+			}
 		case <-s.waitingControllerChan:
 			// closed
 			return s.Error()