kafka-ts 1.1.3 → 1.1.5
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/dist/connection.js +12 -9
- package/package.json +1 -1
package/dist/connection.js
CHANGED
|
@@ -70,10 +70,11 @@ class Connection {
|
|
|
70
70
|
...(connection.host && !(0, net_1.isIP)(connection.host) && { servername: connection.host }),
|
|
71
71
|
}, resolve)
|
|
72
72
|
: net_1.default.connect(connection, resolve);
|
|
73
|
+
this.socket.setKeepAlive(true, 30_000);
|
|
73
74
|
this.socket.once('error', reject);
|
|
74
75
|
});
|
|
75
76
|
this.socket.removeAllListeners('error');
|
|
76
|
-
this.socket.on('error', error => logger_1.log.debug('Socket error', { error }));
|
|
77
|
+
this.socket.on('error', (error) => logger_1.log.debug('Socket error', { error }));
|
|
77
78
|
this.socket.on('data', (data) => this.handleData(data));
|
|
78
79
|
this.socket.once('close', async () => {
|
|
79
80
|
Object.values(this.queue).forEach(({ reject }) => {
|
|
@@ -118,7 +119,7 @@ class Connection {
|
|
|
118
119
|
clearTimeout(timeout);
|
|
119
120
|
try {
|
|
120
121
|
const response = await api.response(responseDecoder);
|
|
121
|
-
(0, assert_1.default)(responseDecoder.getOffset()
|
|
122
|
+
(0, assert_1.default)(responseDecoder.getOffset() === responseSize, `Buffer not correctly consumed: ${responseDecoder.getOffset()} !== ${responseSize}`);
|
|
122
123
|
return response;
|
|
123
124
|
}
|
|
124
125
|
catch (error) {
|
|
@@ -145,23 +146,25 @@ class Connection {
|
|
|
145
146
|
handleData(buffer) {
|
|
146
147
|
this.chunks.push(buffer);
|
|
147
148
|
const decoder = new decoder_1.Decoder(Buffer.concat(this.chunks));
|
|
148
|
-
if (!decoder.canReadBytes(4))
|
|
149
|
+
if (!decoder.canReadBytes(4))
|
|
149
150
|
return;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (size !== decoder.getBufferLength() - 4) {
|
|
151
|
+
const responseSize = decoder.readInt32();
|
|
152
|
+
if (!decoder.canReadBytes(responseSize))
|
|
153
153
|
return;
|
|
154
|
-
|
|
155
|
-
const correlationId =
|
|
154
|
+
const responseDecoder = new decoder_1.Decoder(decoder.read(responseSize));
|
|
155
|
+
const correlationId = responseDecoder.readInt32();
|
|
156
156
|
const context = this.queue[correlationId];
|
|
157
157
|
if (context) {
|
|
158
158
|
delete this.queue[correlationId];
|
|
159
|
-
context.resolve({ responseDecoder
|
|
159
|
+
context.resolve({ responseDecoder, responseSize });
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
162
|
logger_1.log.debug('Could not find pending request for correlationId', { correlationId });
|
|
163
163
|
}
|
|
164
164
|
this.chunks = [];
|
|
165
|
+
const remaining = decoder.read();
|
|
166
|
+
if (remaining.length)
|
|
167
|
+
this.handleData(remaining);
|
|
165
168
|
}
|
|
166
169
|
nextCorrelationId() {
|
|
167
170
|
return this.lastCorrelationId++;
|