(workerId: number)
| 838 | } |
| 839 | |
| 840 | function cleanupWorker(workerId: number) { |
| 841 | const workerInfo = workers.get(workerId) |
| 842 | if (!workerInfo) return |
| 843 | |
| 844 | if (workerInfo.idleTimeout) { |
| 845 | clearTimeout(workerInfo.idleTimeout) |
| 846 | } |
| 847 | |
| 848 | workerInfo.process.kill() |
| 849 | |
| 850 | for (const [id, pending] of workerInfo.pendingExecutions) { |
| 851 | clearTimeout(pending.timeout) |
| 852 | totalActiveExecutions-- |
| 853 | const owner = ownerStates.get(pending.ownerKey) |
| 854 | if (owner) { |
| 855 | owner.activeExecutions = Math.max(0, owner.activeExecutions - 1) |
| 856 | maybeCleanupOwner(owner.ownerKey) |
| 857 | } |
| 858 | pending.resolve({ |
| 859 | result: null, |
| 860 | stdout: '', |
| 861 | error: { |
| 862 | message: 'Code execution failed unexpectedly. Please try again.', |
| 863 | name: 'Error', |
| 864 | isSystemError: true, |
| 865 | }, |
| 866 | }) |
| 867 | workerInfo.pendingExecutions.delete(id) |
| 868 | } |
| 869 | workerInfo.activeExecutions = 0 |
| 870 | |
| 871 | workers.delete(workerId) |
| 872 | } |
| 873 | |
| 874 | function resetWorkerIdleTimeout(workerId: number) { |
| 875 | const workerInfo = workers.get(workerId) |
no test coverage detected