Skip to content

Done handler gets called twice when watch aborts #552

@mariusziemke

Description

@mariusziemke

When trying to do a continuous watch on kubernetes resources I noticed that the done handler gets called twice when the connection to the kubernetes api server aborts unexpectedly.

I don't have time to look deeper into this at the moment, but I guess it's because the error and close events both get fired on the request and both of them trigger the callback function.

Currently I just use a debounce function as a workaround, but we should find a better way of handling this.

Reference:

https://github.com/kubernetes-client/javascript/blob/master/src/watch.ts#L82
https://github.com/kubernetes-client/javascript/blob/master/src/watch.ts#L92

My code:

watchFunction(): void {
    this.watchClient.watch(
      '/api/v1/nodes',
      {},
      async (phase: string, node: V1Node) => {
        // do some magic
      },
      (err) => {
        console.log(`Failed to watch nodes.. restarting watch`);
        this.watchFunction()
      },
    );
}

Workaround:

watchFunction(): void {
    this.watchClient.watch(
      '/api/v1/nodes',
      {},
      async (phase: string, node: V1Node) => {
        // do some magic
      },
      debounce(() => {
        console.log(`Failed to watch nodes.. restarting watch`);
        this.watchFunction();
      }, 1000),
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions