andywer / andywer/threads.js

Crashed worker never resolves promises

Đang mở
#386 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
3.5k
Fork
173
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I have a simple case where if a child terminates, that is never reported back to the application in a way that can be handled.

test-child.ts
```typescript
import { expose } from 'threads/worker'

expose({
async doit(): Promise {
console.log('thread: hello!')
process.exit(1)
},
})
```

run.ts
```typescript
import { spawn, Thread, Worker } from 'threads'

void (async () => {
const thread1 = await spawn(new Worker('./test-child'))

setInterval(() => {
console.log('master: tick')
}, 1000)

Thread.events(thread1).subscribe((event) => console.log('Thread event:', event))

try {
console.log('master: before')

await thread1.doit()
} catch (e) {
console.log('master: it errored', e)
}

console.log('master: we are done')
await Thread.terminate(thread1)
})()
```
Note: the code is written in typescript, but it is being compiled to js before executing, so this shouldnt be something ts-node specific.

The output of this ends up being:
```
threads:master:spawn Initializing new thread +0ms
threads:master:messages Message from worker before finishing initialization: { type: 'init', exposed: { type: 'module', methods: [ 'doit' ] } } +0ms
master: before
threads:master:messages Sending command to run function to worker: { type: 'run', uid: 1, method: 'doit', args: [] } +0ms
thread: hello!
master: tick
master: tick
```
If I remove the setInterval, then it instead immediately terminates, so the worker_thread is definitely terminating.

I would expect a line `master: it errored` to be logged as the call failed, and probably a `Thread event:` too so that the dead worker can be restarted

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.