@@ -12,6 +12,7 @@ import (
1212 "github.com/google/uuid"
1313 "github.com/langgenius/dify-plugin-daemon/internal/types/app"
1414 "github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
15+ "github.com/langgenius/dify-plugin-daemon/pkg/utils/log"
1516)
1617
1718const (
@@ -124,6 +125,15 @@ func (s *PluginInstance) Stop() {
124125// Once the subprocess exists itself, STDOUT always close, which results in `CLOSE STDOUT`
125126func (s * PluginInstance ) StartStdout () {
126127 defer func () {
128+ log .Info (
129+ "plugin stdout reader exiting" ,
130+ "plugin" , s .pluginUniqueIdentifier ,
131+ "instance" , s .ID ()[:8 ],
132+ "started" , s .started ,
133+ "shutdown" , s .shutdown ,
134+ "last_active_at" , s .lastActiveAt ,
135+ "instance_error" , s .Error (),
136+ )
127137 // notify shutdown signal
128138 s .WalkNotifiers (func (notifier PluginInstanceNotifier ) {
129139 notifier .OnInstanceShutdown (s )
@@ -167,6 +177,15 @@ func (s *PluginInstance) StartStdout() {
167177 ),
168178 )
169179 })
180+ } else {
181+ log .Warn (
182+ "plugin stdout reader reached eof" ,
183+ "plugin" , s .pluginUniqueIdentifier ,
184+ "instance" , s .ID ()[:8 ],
185+ "started" , s .started ,
186+ "shutdown" , s .shutdown ,
187+ "last_active_at" , s .lastActiveAt ,
188+ )
170189 }
171190
172191 // once reader of stdout is closed, kill subprocess
@@ -176,13 +195,37 @@ func (s *PluginInstance) StartStdout() {
176195 s .WalkNotifiers (func (notifier PluginInstanceNotifier ) {
177196 notifier .OnInstanceErrorLog (s , fmt .Errorf ("failed to kill subprocess: %s" , err .Error ()))
178197 })
198+ log .Warn (
199+ "plugin subprocess kill returned" ,
200+ "plugin" , s .pluginUniqueIdentifier ,
201+ "instance" , s .ID ()[:8 ],
202+ "error" , err ,
203+ )
204+ } else {
205+ log .Warn (
206+ "plugin subprocess killed after stdout closed" ,
207+ "plugin" , s .pluginUniqueIdentifier ,
208+ "instance" , s .ID ()[:8 ],
209+ )
179210 }
180211
181212 // collect subprocess, avoid zombie processes
182213 if _ , err := s .cmd .Process .Wait (); err != nil {
183214 s .WalkNotifiers (func (notifier PluginInstanceNotifier ) {
184215 notifier .OnInstanceErrorLog (s , fmt .Errorf ("failed to reap subprocess: %s" , err .Error ()))
185216 })
217+ log .Warn (
218+ "plugin subprocess wait returned error" ,
219+ "plugin" , s .pluginUniqueIdentifier ,
220+ "instance" , s .ID ()[:8 ],
221+ "error" , err ,
222+ )
223+ } else {
224+ log .Info (
225+ "plugin subprocess reaped" ,
226+ "plugin" , s .pluginUniqueIdentifier ,
227+ "instance" , s .ID ()[:8 ],
228+ )
186229 }
187230}
188231
@@ -282,6 +325,13 @@ func (s *PluginInstance) Monitor() error {
282325
283326 // check heartbeat
284327 if time .Since (s .lastActiveAt ) > MAX_HEARTBEAT_INTERVAL {
328+ log .Warn (
329+ "plugin instance marked inactive" ,
330+ "plugin" , s .pluginUniqueIdentifier ,
331+ "instance" , s .ID ()[:8 ],
332+ "inactive_seconds" , time .Since (s .lastActiveAt ).Seconds (),
333+ "instance_error" , s .Error (),
334+ )
285335 s .WalkNotifiers (func (notifier PluginInstanceNotifier ) {
286336 // notify handlers
287337 notifier .OnInstanceLaunchFailed (
0 commit comments