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

Reconnection is not supported #72

Open
winnochan opened this issue Mar 23, 2021 · 18 comments
Open

Reconnection is not supported #72

winnochan opened this issue Mar 23, 2021 · 18 comments

Comments

@winnochan
Copy link

When connection with elasticsearch server is broken, it won't send any msg to server any more. Can you add this feature?

@mcollina
Copy link
Member

@delvedor maybe you can help?

Otherwise it would be good for you to send a PR.

@alexandrevanhoutte
Copy link

Is there any update about this feature?
Is there a temporary solution to resolve it ?

@mcollina
Copy link
Member

@alexandrevanhoutte
Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@penumbra23
Copy link

We're experiencing the same issue, once the ES instance crashes or any network congestion hits the roof, the connection gets broken. While inspecting the ClientOptions inside @elastic/elasticsearch-js, there's the following field:

resurrectStrategy?: 'ping' | 'optimistic' | 'none'

Maybe setting this one to ping should be sufficient for the problem?

@mcollina
Copy link
Member

Maybe? Would you like to send a PR?

@penumbra23
Copy link

I can give it a try 😄

@delvedor
Copy link
Collaborator

@penumbra23 it won't solve this specific issue out if the box, the the v8 client uses a new type of connection pool.

Try to use ClusterConnectionPool in the client configuration, the ping is the default behavior.

It would be useful to understand why the client can't reconnect. The connection pool will retry connection either way after a while. It might be something related to the underlying http library itself.

@Granjow
Copy link

Granjow commented Jan 26, 2023

I have a service which, on startup, sometimes logs the following from a pino-elasticsearch error event:

connect ENETUNREACH 10.10.10.100:9200 - Local (0.0.0.0:0)

It will then never try to reconnect again until I restart the service. Before that, I see that elasticsearch retries sending messages several times when setting the environment variable DEBUG=elasticsearch.

  elasticsearch Retrying request, there are still 0 attempts {
  path: '/_bulk',
  method: 'POST',
  querystring: {},
  bulkBody: [
    // (data here)
  ]
} +6ms
  elasticsearch Starting a new request {
  method: 'POST',
  path: '/_bulk',
  body: 'DATA',
  querystring: '',
  headers: {
    'user-agent': 'elastic-transport-js/8.2.0 (linux 5.10.103-v7l+-arm; Node.js v18.13.0)',
    'x-elastic-client-meta': 'es=8.5.0,js=18.13.0,t=8.2.0,hc=18.13.0,h=bp',
    'content-type': 'application/vnd.elasticsearch+x-ndjson; compatible-with=8',
    accept: 'application/vnd.elasticsearch+json; compatible-with=8',
    'content-length': '1175'
  }
} +6ms

After the pino-elasticsearch error, nothing from elasticsearch is logged anymore.

Does this help fixing the issue?

@padenaa
Copy link

padenaa commented Mar 27, 2023

Is there any plan for reconnection to be implemented as a feature? I'm doing some development that could benefit from it

@mcollina
Copy link
Member

My hope is that somebody will eventually send a PR for this. I currently do not have time.

@sheldhur
Copy link
Contributor

sheldhur commented Jul 17, 2023

The main problem in elasticsearch elastic/elastic-transport-js#53

I can try fix it and make PR but before I want to be sure that it isn't in vain, because my implementation will do the same elasticsearch is trying to do, but only after the client emits error.

https://github.com/elastic/elastic-transport-js/blob/0c9b7c56089c68efaa5a5bc93d85220cbeb06d56/src/pool/ClusterConnectionPool.ts#L160-L192

It'll help me if somebody has a ready solution and you can publish it in this thread.

@sheldhur
Copy link
Contributor

It was a little easier)

@mcollina
Copy link
Member

trhx

@Suniron
Copy link

Suniron commented Sep 26, 2023

How can I set a resurrect strategy? Is there a way?

@sheldhur
Copy link
Contributor

sheldhur commented Nov 20, 2023

@mcollina @delvedor can you reopen this issue? Sometimes I keep seeing this problem in my production. I have a single node ES and ~50% services can't restore connection after restarting node.

I think my PR closed #140 issue, but not this.

@paulish
Copy link

paulish commented Nov 21, 2023

Yes, have the same problem. If at the start of process the elasticsearch node is not available then you have no logs before process restart.

@mcollina mcollina reopened this Nov 21, 2023
@mcollina
Copy link
Member

Would you like to send a PR?

@sheldhur
Copy link
Contributor

sheldhur commented Nov 21, 2023

@mcollina that client problem
elastic/elasticsearch-js#1714
elastic/elastic-transport-js#53

I can share my dirty hack like as a temporary solution which just ignore all connection errors

import { UndiciConnection } from '@elastic/transport';

export class IgnoreErrorConnection extends UndiciConnection {
  constructor(opts) {
    super(opts);
    this.requestAfter = null;
    this.requestAfterInterval = 5 * 60000;
  }

  async request(params, options) {
    const now = new Date();
    if (this.requestAfter && this.requestAfter > now) {
      return this.fakeResponse(params);
    }

    try {
      const response = await super.request(params, options);
      this.requestAfter = null;

      return response;
    } catch (err) {
      switch (err.name) {
        case 'TimeoutError':
        case 'ConnectionError': {
          this.requestAfter = new Date(now.valueOf() + this.requestAfterInterval);
          return this.fakeResponse(params);
        }
        default: {
          throw err;
        }
      }
    }
  }

  fakeResponse(params) {
    const docs = params.body.split('\n').length;
    const result = {
      errors: false,
      took: docs,
      items: Array(docs).fill({ result: 'created', status: 201 })
    };
    const body = JSON.stringify(result);

    return {
      statusCode: 200,
      headers: {
        'content-type': 'application/vnd.elasticsearch+json;compatible-with=8',
        'content-length': body.length,
        'x-elastic-product': 'Elasticsearch'
      },
      body
    };
  }
}

const elastic = pinoElastic({
  ...
  Connection: IgnoreErrorConnection,
  ...
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants