bare-rpc 1.3.5 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +42 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -64,6 +64,14 @@ module.exports = exports = class RPC {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
_sendMessage(message, cb) {
|
|
67
|
+
// Once the underlying stream is being torn down there is nowhere left to
|
|
68
|
+
// write, so drop the message and settle the callback immediately. This
|
|
69
|
+
// keeps stream teardown from stalling on a drain that will never arrive.
|
|
70
|
+
if (this._stream.destroying) {
|
|
71
|
+
if (cb) cb(null)
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
67
75
|
const header = c.encode(m.header, message)
|
|
68
76
|
|
|
69
77
|
let flushed = this._stream.write(header)
|
|
@@ -169,7 +177,40 @@ module.exports = exports = class RPC {
|
|
|
169
177
|
_onerror(err) {
|
|
170
178
|
this._ondrain(err)
|
|
171
179
|
|
|
172
|
-
//
|
|
180
|
+
// Reject any request awaiting a plain reply. Requests whose response is
|
|
181
|
+
// delivered over a stream are torn down through that stream below.
|
|
182
|
+
for (const request of this._outgoingRequests.values()) {
|
|
183
|
+
if (request.received && request._responseStream === null) request._reject(err)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Collect the streams first, deduplicating as a single request may appear
|
|
187
|
+
// in more than one map, then destroy them once the maps have been cleared.
|
|
188
|
+
const streams = new Set()
|
|
189
|
+
|
|
190
|
+
for (const request of this._outgoingRequests.values()) {
|
|
191
|
+
if (request._requestStream !== null) streams.add(request._requestStream)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
for (const request of this._incomingRequests.values()) {
|
|
195
|
+
if (request._requestStream !== null) streams.add(request._requestStream)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
for (const request of this._outgoingResponses.values()) {
|
|
199
|
+
if (request._responseStream !== null) streams.add(request._responseStream)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (const request of this._incomingResponses.values()) {
|
|
203
|
+
if (request._responseStream !== null) streams.add(request._responseStream)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
this._outgoingRequests.clear()
|
|
207
|
+
this._outgoingResponses.clear()
|
|
208
|
+
this._incomingRequests.clear()
|
|
209
|
+
this._incomingResponses.clear()
|
|
210
|
+
this._pendingRequests.clear()
|
|
211
|
+
this._pendingResponses.clear()
|
|
212
|
+
|
|
213
|
+
for (const stream of streams) stream.destroy(err)
|
|
173
214
|
}
|
|
174
215
|
|
|
175
216
|
_ondata(data) {
|