Miguel Serrano 7 лет назад
Родитель
Сommit
46d0cf9c4b
1 измененных файлов с 21 добавлено и 3 удалено
  1. 21 3
      services/spelling/app/js/ASpellWorker.js

+ 21 - 3
services/spelling/app/js/ASpellWorker.js

@@ -19,6 +19,7 @@ class ASpellWorker {
   constructor(language) {
   constructor(language) {
     this.language = language
     this.language = language
     this.count = 0
     this.count = 0
+    this.closeReason = ''
     this.pipe = childProcess.spawn('aspell', [
     this.pipe = childProcess.spawn('aspell', [
       'pipe',
       'pipe',
       '-t',
       '-t',
@@ -43,19 +44,29 @@ class ASpellWorker {
       })
       })
     })
     })
     this.pipe.on('close', () => {
     this.pipe.on('close', () => {
+      const previousWorkerState = this.state
       if (this.state !== 'killed') {
       if (this.state !== 'killed') {
         this.state = 'closed'
         this.state = 'closed'
       }
       }
       if (this.callback != null) {
       if (this.callback != null) {
         const err = new errorType.Error({
         const err = new errorType.Error({
           message: 'aspell worker closed output streams with uncalled callback',
           message: 'aspell worker closed output streams with uncalled callback',
-          info: { process: this.pipe.pid, lang: this.language }
+          info: {
+            process: this.pipe.pid,
+            lang: this.language,
+            stdout: output.slice(-1024),
+            stderr: error.slice(-1024),
+            workerState: this.state,
+            previousWorkerState,
+            closeReason: this.closeReason
+          }
         })
         })
         this.callback(err, [])
         this.callback(err, [])
         this.callback = null
         this.callback = null
       }
       }
     })
     })
     this.pipe.on('error', err => {
     this.pipe.on('error', err => {
+      const previousWorkerState = this.state
       if (this.state !== 'killed') {
       if (this.state !== 'killed') {
         this.state = 'error'
         this.state = 'error'
       }
       }
@@ -64,7 +75,9 @@ class ASpellWorker {
         stdout: output.slice(-1024),
         stdout: output.slice(-1024),
         stderr: error.slice(-1024),
         stderr: error.slice(-1024),
         lang: this.language,
         lang: this.language,
-        workerState: this.state
+        workerState: this.state,
+        previousWorkerState,
+        closeReason: this.closeReason
       }
       }
 
 
       if (this.callback != null) {
       if (this.callback != null) {
@@ -81,6 +94,7 @@ class ASpellWorker {
       }
       }
     })
     })
     this.pipe.stdin.on('error', err => {
     this.pipe.stdin.on('error', err => {
+      const previousWorkerState = this.state
       if (this.state !== 'killed') {
       if (this.state !== 'killed') {
         this.state = 'error'
         this.state = 'error'
       }
       }
@@ -89,7 +103,9 @@ class ASpellWorker {
         stdout: output.slice(-1024),
         stdout: output.slice(-1024),
         stderr: error.slice(-1024),
         stderr: error.slice(-1024),
         lang: this.language,
         lang: this.language,
-        workerState: this.state
+        workerState: this.state,
+        previousWorkerState,
+        closeReason: this.closeReason
       }
       }
 
 
       if (this.callback != null) {
       if (this.callback != null) {
@@ -199,11 +215,13 @@ class ASpellWorker {
   shutdown(reason) {
   shutdown(reason) {
     logger.info({ process: this.pipe.pid, reason }, 'shutting down')
     logger.info({ process: this.pipe.pid, reason }, 'shutting down')
     this.state = 'closing'
     this.state = 'closing'
+    this.closeReason = reason
     return this.pipe.stdin.end()
     return this.pipe.stdin.end()
   }
   }
 
 
   kill(reason) {
   kill(reason) {
     logger.info({ process: this.pipe.pid, reason }, 'killing')
     logger.info({ process: this.pipe.pid, reason }, 'killing')
+    this.closeReason = reason
     if (this.state === 'killed') {
     if (this.state === 'killed') {
       return
       return
     }
     }