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