pulsar-client 1.11.0-rc.2 → 1.11.0-rc.3
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/package.json +1 -1
- package/src/Reader.cc +13 -11
- package/tests/reader.test.js +41 -0
package/package.json
CHANGED
package/src/Reader.cc
CHANGED
|
@@ -60,17 +60,19 @@ struct ReaderListenerProxyData {
|
|
|
60
60
|
void ReaderListenerProxy(Napi::Env env, Napi::Function jsCallback, ReaderListenerProxyData *data) {
|
|
61
61
|
Napi::Object msg = Message::NewInstance({}, data->cMessage);
|
|
62
62
|
Reader *reader = data->reader;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
// `reader` might be null in certain cases, segmentation fault might happend without this null check.
|
|
64
|
+
if (reader) {
|
|
65
|
+
Napi::Value ret = jsCallback.Call({msg, reader->Value()});
|
|
66
|
+
if (ret.IsPromise()) {
|
|
67
|
+
Napi::Promise promise = ret.As<Napi::Promise>();
|
|
68
|
+
Napi::Value thenValue = promise.Get("then");
|
|
69
|
+
if (thenValue.IsFunction()) {
|
|
70
|
+
Napi::Function then = thenValue.As<Napi::Function>();
|
|
71
|
+
Napi::Function callback =
|
|
72
|
+
Napi::Function::New(env, [data](const Napi::CallbackInfo &info) { data->callback(); });
|
|
73
|
+
then.Call(promise, {callback});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
data->callback();
|
package/tests/reader.test.js
CHANGED
|
@@ -130,5 +130,46 @@ const baseUrl = 'http://localhost:8080';
|
|
|
130
130
|
await reader.close();
|
|
131
131
|
await client.close();
|
|
132
132
|
});
|
|
133
|
+
|
|
134
|
+
test('Reader should not throw segmentation fault when create and close', async () => {
|
|
135
|
+
const NUM_ITS = 1000;
|
|
136
|
+
const its = Array.from({ length: NUM_ITS }, (_, i) => i);
|
|
137
|
+
|
|
138
|
+
const client = new Pulsar.Client({
|
|
139
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const producer = await client.createProducer({
|
|
143
|
+
topic: 'persistent://public/default/my-topic',
|
|
144
|
+
sendTimeoutMs: 30000,
|
|
145
|
+
batchingEnabled: true,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Send messages
|
|
149
|
+
for (let i = 0; i < 10; i += 1) {
|
|
150
|
+
const msg = `my-message-${i}`;
|
|
151
|
+
producer.send({
|
|
152
|
+
data: Buffer.from(msg),
|
|
153
|
+
});
|
|
154
|
+
console.log(`Sent message: ${msg}`);
|
|
155
|
+
}
|
|
156
|
+
await producer.flush();
|
|
157
|
+
|
|
158
|
+
await Promise.all(
|
|
159
|
+
its.map(async () => {
|
|
160
|
+
const reader = await client.createReader({
|
|
161
|
+
topic: 'persistent://public/default/my-topic',
|
|
162
|
+
startMessageId: Pulsar.MessageId.earliest(),
|
|
163
|
+
listener: (message) => {
|
|
164
|
+
console.log(message.getData().toString());
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
await reader.close();
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
await producer.close();
|
|
171
|
+
await client.close();
|
|
172
|
+
expect(true).toBe(true);
|
|
173
|
+
});
|
|
133
174
|
});
|
|
134
175
|
})();
|