Skip to content

Commit

Permalink
5.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mceachen committed Feb 11, 2020
1 parent 7c427f6 commit 762d68b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 64 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ See [Semver](http://semver.org/).
- 🐞 Backwards-compatible bug fixes
- 📦 Minor packaging changes

## v5.9.3

- 🐞 `BatchProcess`'s streams could cause an infinite loop on `.end()` when
`stdout` was destroyed.
- 📦 Updated deps

## v5.9.2

- 🐞 `BatchProcess.ready` now verifies the child process still exists
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
"author": "Matthew McEachen <matthew-batchcluster@mceachen.org>",
"license": "MIT",
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/chai": "^4.2.9",
"@types/chai-as-promised": "^7.1.2",
"@types/chai-string": "^1.4.2",
"@types/mocha": "^5.2.7",
"@types/node": "^13.5.0",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"@types/mocha": "^7.0.1",
"@types/node": "^13.7.1",
"@typescript-eslint/eslint-plugin": "^2.19.2",
"@typescript-eslint/eslint-plugin-tslint": "^2.19.2",
"@typescript-eslint/parser": "^2.19.2",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-string": "^1.5.0",
"chai-withintoleranceof": "^1.0.1",
"eslint": "^6.8.0",
"mocha": "^7.0.0",
"mocha": "^7.0.1",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"rimraf": "^3.0.2",
"seedrandom": "^3.0.5",
"serve": "^11.3.0",
"source-map-support": "^0.5.16",
Expand Down
37 changes: 22 additions & 15 deletions src/BatchProcess.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as _cp from "child_process"

import { debounce, until, delay } from "./Async"
import { debounce, delay, until } from "./Async"
import { logger } from "./BatchCluster"
import { BatchProcessObserver } from "./BatchProcessObserver"
import { Deferred } from "./Deferred"
Expand All @@ -9,7 +8,8 @@ import { InternalBatchProcessOptions } from "./InternalBatchProcessOptions"
import { map } from "./Object"
import { SimpleParser } from "./Parser"
import { kill, pidExists } from "./Pids"
import { ensureSuffix, toS, blank } from "./String"
import { mapNotDestroyed } from "./Stream"
import { blank, ensureSuffix, toS } from "./String"
import { Task } from "./Task"

/**
Expand Down Expand Up @@ -139,14 +139,18 @@ export class BatchProcess {
// This must not be async, or new instances aren't started as busy (until the
// startup task is complete)
execTask(task: Task<any>): boolean {
if (this.proc.stdin == null || this.proc.stdin.destroyed) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.end(false, "proc.stdin is null or destroyed")
return false
}

// We're not going to run this.running() here, because BatchCluster will
// already have pruned the processes that have exitted unexpectedly just
// milliseconds ago.
if (this._taskCount >= 0 && !this.ready) {
this.observer.onInternalError(
new Error(
`${this.name}.execTask(${task.command}): not ready`
)
new Error(`${this.name}.execTask(${task.command}): not ready`)
)
return false
}
Expand Down Expand Up @@ -182,7 +186,7 @@ export class BatchProcess {
}
})
try {
this.proc.stdin!.write(cmd)
this.proc.stdin.write(cmd)
return true
} catch (err) {
// child process went away. We should too.
Expand Down Expand Up @@ -240,9 +244,9 @@ export class BatchProcess {

// proc cleanup:
tryEach([
() => map(this.proc.stdin, ea => ea.end(cmd)),
() => map(this.proc.stdout, ea => ea.destroy()),
() => map(this.proc.stderr, ea => ea.destroy()),
() => mapNotDestroyed(this.proc.stdin, ea => ea.end(cmd)),
() => mapNotDestroyed(this.proc.stdout, ea => ea.destroy()),
() => mapNotDestroyed(this.proc.stderr, ea => ea.destroy()),
() => this.proc.disconnect()
])

Expand Down Expand Up @@ -281,11 +285,14 @@ export class BatchProcess {
if (this._endPromise != null) {
// We're ending already, so don't propogate the error.
// This is expected due to race conditions stdin EPIPE and process shutdown.
logger().debug(this.name + ".onError() post-end (expected and not propagated)", {
source,
_error,
task
})
logger().debug(
this.name + ".onError() post-end (expected and not propagated)",
{
source,
_error,
task
}
)
return
}
if (task == null) {
Expand Down
9 changes: 8 additions & 1 deletion src/Stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Writable } from "stream"
import { Readable, Writable } from "stream"

export function end(endable: Writable, contents?: string): Promise<void> {
return new Promise<void>(resolve => endable.end(contents, resolve))
}

export function mapNotDestroyed<T extends Readable | Writable, R>(
obj: T | undefined | null,
f: (t: T) => R
): R | undefined {
return obj != null && !obj.destroyed ? f(obj) : undefined
}
88 changes: 48 additions & 40 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.6.tgz#a55625d151d9c7c7a0a95920632131d66480bce9"
integrity sha512-HF8faEUA4JurIm+68VaA2KedtZf5LYdXpQEAbIAN79DwWQbO82BNTksZgCH3UMqbZHXex9C6TrBfg7OUInRISQ==

"@types/chai@^4.2.7":
version "4.2.7"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.7.tgz#1c8c25cbf6e59ffa7d6b9652c78e547d9a41692d"
integrity sha512-luq8meHGYwvky0O7u0eQZdA7B4Wd9owUCqvbw2m3XCrCU8mplYOujMBbvyS547AxJkC+pGnd0Cm15eNxEUNU8g==
"@types/chai@^4.2.9":
version "4.2.9"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.2.9.tgz#194332625ed2ae914aef00b8d5ca3b77e7924cc6"
integrity sha512-NeXgZj+MFL4izGqA4sapdYzkzQG+MtGra9vhQ58dnmDY++VgJaRUws+aLVV5zRJCYJl/8s9IjMmhiUw1WsKSmw==

"@types/eslint-visitor-keys@^1.0.0":
version "1.0.0"
Expand All @@ -57,50 +57,58 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/mocha@^5.2.7":
version "5.2.7"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==
"@types/mocha@^7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-7.0.1.tgz#5d7ec2a789a1f77c59b7ad071b9d50bf1abbfc9e"
integrity sha512-L/Nw/2e5KUaprNJoRA33oly+M8X8n0K+FwLTbYqwTcR14wdPWeRkigBLfSFpN/Asf9ENZTMZwLxjtjeYucAA4Q==

"@types/node@^13.7.1":
version "13.7.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.1.tgz#238eb34a66431b71d2aaddeaa7db166f25971a0d"
integrity sha512-Zq8gcQGmn4txQEJeiXo/KiLpon8TzAl0kmKH4zdWctPj05nWwp1ClMdAVEloqrQKfaC48PNLdgN/aVaLqUrluA==

"@types/node@^13.5.0":
version "13.5.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.5.0.tgz#4e498dbf355795a611a87ae5ef811a8660d42662"
integrity sha512-Onhn+z72D2O2Pb2ql2xukJ55rglumsVo1H6Fmyi8mlU9SvKdBk/pUSUAiBY/d9bAOF7VVWajX3sths/+g6ZiAQ==
"@typescript-eslint/eslint-plugin-tslint@^2.19.2":
version "2.19.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin-tslint/-/eslint-plugin-tslint-2.19.2.tgz#78b1def7370077ef48aa008070eb17dd37318372"
integrity sha512-S6F+Iaq3WIZN1aj6ar9Obda6kF3UaRWzT1Phi/CGp0mrSuaO1g8G+VJ0QG2HJ7S7CIKXMy7zXmF2alZ38EIVzw==
dependencies:
"@typescript-eslint/experimental-utils" "2.19.2"
lodash "^4.17.15"

"@typescript-eslint/eslint-plugin@^2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.17.0.tgz#880435a9f9bdd50b45fa286ba63fed723d73c837"
integrity sha512-tg/OMOtPeXlvk0ES8mZzEZ4gd1ruSE03nsKcK+teJhxYv5CPCXK6Mb/OK6NpB4+CqGTHs4MVeoSZXNFqpT1PyQ==
"@typescript-eslint/eslint-plugin@^2.19.2":
version "2.19.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.19.2.tgz#e279aaae5d5c1f2547b4cff99204e1250bc7a058"
integrity sha512-HX2qOq2GOV04HNrmKnTpSIpHjfl7iwdXe3u/Nvt+/cpmdvzYvY0NHSiTkYN257jHnq4OM/yo+OsFgati+7LqJA==
dependencies:
"@typescript-eslint/experimental-utils" "2.17.0"
"@typescript-eslint/experimental-utils" "2.19.2"
eslint-utils "^1.4.3"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
tsutils "^3.17.1"

"@typescript-eslint/experimental-utils@2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.17.0.tgz#12ed4a5d656e02ff47a93efc7d1ce1b8f1242351"
integrity sha512-2bNf+mZ/3mj5/3CP56v+ldRK3vFy9jOvmCPs/Gr2DeSJh+asPZrhFniv4QmQsHWQFPJFWhFHgkGgJeRmK4m8iQ==
"@typescript-eslint/experimental-utils@2.19.2":
version "2.19.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.19.2.tgz#4611d44cf0f0cb460c26aa7676fc0a787281e233"
integrity sha512-B88QuwT1wMJR750YvTJBNjMZwmiPpbmKYLm1yI7PCc3x0NariqPwqaPsoJRwU9DmUi0cd9dkhz1IqEnwfD+P1A==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "2.17.0"
"@typescript-eslint/typescript-estree" "2.19.2"
eslint-scope "^5.0.0"

"@typescript-eslint/parser@^2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.17.0.tgz#627f79586d868edbab55f46a6b183cdc341aea1d"
integrity sha512-k1g3gRQ4fwfJoIfgUpz78AovicSWKFANmvTfkAHP24MgJHjWfZI6ya7tsQZt1sLczvP4G9BE5G5MgADHdmJB/w==
"@typescript-eslint/parser@^2.19.2":
version "2.19.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.19.2.tgz#21f42c0694846367e7d6a907feb08ab2f89c0879"
integrity sha512-8uwnYGKqX9wWHGPGdLB9sk9+12sjcdqEEYKGgbS8A0IvYX59h01o8os5qXUHMq2na8vpDRaV0suTLM7S8wraTA==
dependencies:
"@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "2.17.0"
"@typescript-eslint/typescript-estree" "2.17.0"
"@typescript-eslint/experimental-utils" "2.19.2"
"@typescript-eslint/typescript-estree" "2.19.2"
eslint-visitor-keys "^1.1.0"

"@typescript-eslint/typescript-estree@2.17.0":
version "2.17.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.17.0.tgz#2ce1531ec0925ef8d22d7026235917c2638a82af"
integrity sha512-g0eVRULGnEEUakxRfJO0s0Hr1LLQqsI6OrkiCLpdHtdJJek+wyd8mb00vedqAoWldeDcOcP8plqw8/jx9Gr3Lw==
"@typescript-eslint/typescript-estree@2.19.2":
version "2.19.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.19.2.tgz#67485b00172f400474d243c6c0be27581a579350"
integrity sha512-Xu/qa0MDk6upQWqE4Qy2X16Xg8Vi32tQS2PR0AvnT/ZYS4YGDvtn2MStOh5y8Zy2mg4NuL06KUHlvCh95j9C6Q==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
Expand Down Expand Up @@ -1218,10 +1226,10 @@ mkdirp@0.5.1, mkdirp@^0.5.1:
dependencies:
minimist "0.0.8"

mocha@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.0.0.tgz#c60d14bf3de9601f549b3ff5be657eb8381c54bf"
integrity sha512-CirsOPbO3jU86YKjjMzFLcXIb5YiGLUrjrXFHoJ3e2z9vWiaZVCZQ2+gtRGMPWF+nFhN6AWwLM/juzAQ6KRkbA==
mocha@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.0.1.tgz#276186d35a4852f6249808c6dd4a1376cbf6c6ce"
integrity sha512-9eWmWTdHLXh72rGrdZjNbG3aa1/3NRPpul1z0D979QpEnFdCG0Q5tv834N+94QEN2cysfV72YocQ3fn87s70fg==
dependencies:
ansi-colors "3.2.3"
browser-stdout "1.3.1"
Expand Down Expand Up @@ -1581,10 +1589,10 @@ rimraf@2.6.3:
dependencies:
glob "^7.1.3"

rimraf@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.0.tgz#614176d4b3010b75e5c390eb0ee96f6dc0cebb9b"
integrity sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==
rimraf@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
dependencies:
glob "^7.1.3"

Expand Down

0 comments on commit 762d68b

Please sign in to comment.