Skip to content

Conversation

@BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Jun 14, 2022

There is a segmentation fault reported by a user.

So, I recompiled the extension with node-gyp rebuild --debug then attached a debugger and it crashed because of this

(gdb) l 60 void MessageListenerProxy(Napi::Env env, Napi::Function jsCallback, MessageListenerProxyData *data) { 61 Napi::Object msg = Message::NewInstance({}, data->cMessage); 62 Consumer *consumer = data->consumer; 63 delete data; 64 65 jsCallback.Call({msg, consumer->Value()}); 66 } 67 68 void MessageListener(pulsar_consumer_t *cConsumer, pulsar_message_t *cMessage, void *ctx) { 69 ListenerCallback *listenerCallback = (ListenerCallback *)ctx; (gdb) 

On line 65, consumer is actually null

The consumer field is assigned from MessageListenerCallback and the initial value is nullptr. This field could only be modified in Consumer::SetListenerCallback. I didn't look deeper into where it's invoked, but I think it's better to add the null check here for safety.

delete data;

jsCallback.Call({msg, consumer->Value()});
if (consumer) {
Copy link
Contributor

@gaoran10 gaoran10 Jun 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to print some warning messages when the consumer is a null value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The initial value is null. And I found the NodeJS wrapper never logs any message. Even if you added a log here, there is still helpless to find in which scenario consumer is null here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if users lose to handle some messages when the consumer is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the controversial point is whether should we skip the null consumer.

  • Yes: might lose messages (not sure)
  • No: fast fail

Adding logs doesn't solve anything. There is no logger in NodeJS client, printing logs to console is meaningless and helpless as I said.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need more info to reproduce the segmentation fault. But for now, a safe solution is to avoid accessing a null consumer.

@k2la
Copy link
Contributor

k2la commented Jul 8, 2022

@BewareMyPower
This fix does not address the root cause.
Could you additionally write comments indicating that this modification is workaround?

Also, what versions of client libraries(pulsar-client-node and pulsar-client-cpp) were used when this segmentation fault occurred?

@BewareMyPower
Copy link
Contributor Author

Yeah. And I'll confirm the version from the user

@k2la k2la merged commit 8893e47 into apache:master Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment