Sfoglia il codice sorgente

fix: increase buffer size of stdout scanner to prevent scanner errors

Yeuoly 8 mesi fa
parent
commit
c0ff708a99

+ 7 - 2
internal/core/plugin_manager/aws_manager/io.go

@@ -83,9 +83,14 @@ func (r *AWSPluginRuntime) Write(session_id string, data []byte) {
 
 		// write to data stream
 		scanner := bufio.NewScanner(response.Body)
+
+		// TODO: set a reasonable buffer size or use a reader, this is a temporary solution
+		scanner.Buffer(make([]byte, 1024), 5*1024*1024)
+
 		sessionAlive := true
 		for scanner.Scan() && sessionAlive {
 			bytes := scanner.Bytes()
+
 			if len(bytes) == 0 {
 				continue
 			}
@@ -120,12 +125,12 @@ func (r *AWSPluginRuntime) Write(session_id string, data []byte) {
 			)
 		}
 
-		if scanner.Err() != nil {
+		if err := scanner.Err(); err != nil {
 			l.Send(plugin_entities.SessionMessage{
 				Type: plugin_entities.SESSION_MESSAGE_TYPE_ERROR,
 				Data: parser.MarshalJsonBytes(plugin_entities.ErrorResponse{
 					ErrorType: "PluginDaemonInnerError",
-					Message:   fmt.Sprintf("failed to read response body: %v", scanner.Err()),
+					Message:   fmt.Sprintf("failed to read response body: %v", err),
 				}),
 			})
 		}

+ 9 - 0
internal/core/plugin_manager/local_manager/stdio_handle.go

@@ -79,8 +79,13 @@ func (s *stdioHolder) StartStdout(notify_heartbeat func()) {
 	defer s.Stop()
 
 	scanner := bufio.NewScanner(s.reader)
+
+	// TODO: set a reasonable buffer size or use a reader, this is a temporary solution
+	scanner.Buffer(make([]byte, 1024), 5*1024*1024)
+
 	for scanner.Scan() {
 		data := scanner.Bytes()
+
 		if len(data) == 0 {
 			continue
 		}
@@ -110,6 +115,10 @@ func (s *stdioHolder) StartStdout(notify_heartbeat func()) {
 			},
 		)
 	}
+
+	if err := scanner.Err(); err != nil {
+		log.Error("plugin %s has an error on stdout: %s", s.pluginUniqueIdentifier, err)
+	}
 }
 
 // WriteError writes the error message to the stdio holder