Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Fixed an issue where clients were unintentionally disconnected #348

Closed
wants to merge 1 commit into from

Conversation

kontotto
Copy link
Contributor

This PR fixes an issue where client connections could be unintentionally disconnected.

Motivation

In the code below, which is a modified version of examples/consumer_listener.js, the connection is disconnected after a few seconds. I want to fix it.

const Pulsar = require('../');

(async () => {
  // Create a client
  const client = new Pulsar.Client({
    serviceUrl: 'pulsar://localhost:6650',
  });

  Pulsar.Client.setLogHandler((level, file, line, message) => {
        console.log('[%s][%s:%d] %s', level, file, line, message);
    });

  // Create a consumer with listener
  const consumer = await client.subscribe({
    topic: 'persistent://public/default/my-topic',
    subscription: 'sub1',
    subscriptionType: 'Shared',
    listener: (msg, msgConsumer) => {
      console.log(msg.getData().toString());
      msgConsumer.acknowledge(msg);
    },
  });
})();
[1][Client:90] Subscribing on Topic :persistent://public/default/my-topic
[1][ClientConnection:184] [<none> -> pulsar://localhost:6650] Create ClientConnection, timeout=10000
[1][ConnectionPool:106] Created connection for pulsar://localhost:6650
[1][ClientConnection:382] [127.0.0.1:52044 -> 127.0.0.1:6650] Connected to broker
[1][HandlerBase:72] [0x600000be2f88, sub1, 0] Getting connection from pool
[1][ConsumerImpl:282] [0x600000be2f88, sub1, 0] Created consumer on broker [127.0.0.1:52044 -> 127.0.0.1:6650]
[1][ClientConnection:1236] [127.0.0.1:52044 -> 127.0.0.1:6650] Connection disconnected

Modifications

Extend cClient lifetime prevents it from being released

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

@shibd shibd self-requested a review October 31, 2023 02:33
@shibd shibd added this to the 1.10.0 milestone Oct 31, 2023
@kontotto kontotto marked this pull request as draft October 31, 2023 02:36
@kontotto
Copy link
Contributor Author

I noticed that this change leaks memory, so I made it into a draft once.

@kontotto
Copy link
Contributor Author

kontotto commented Nov 6, 2023

I found that it has the same issues as pulsar-client-cpp, so I close it.

@kontotto kontotto closed this Nov 6, 2023
@kontotto kontotto deleted the fix_client_scope branch November 6, 2023 08:43
@shibd shibd removed this from the 1.10.0 milestone Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants