http-proxy-middleware icon indicating copy to clipboard operation
http-proxy-middleware copied to clipboard

SSE close connection issue with proxy

Open swapnil-bhalekar opened this issue 1 year ago • 3 comments

Checks

Describe the bug (be clear and concise)

When we deploy web application for SSE in argocd with nginx server we are not able close SSE server connection on closing of event stream. For front end we are using Angular 16 and for backend service we are using NodeJS

Step-by-step reproduction instructions

1. From angular we are using event source for calling proxy middleware which will connect to backend services.
 
  this.eventSource = new EventSource("host/event/api");

2)   app.use('/event/*', createProxyMiddleware(options));
  On receiving this request on middleware, it will subscribe to close event.
3) On closing of tab we are calling this.eventSource.close() which should close proxy event.
Its working in local but with argoCD we are not able to receive close event.

Expected behavior (be clear and concise)

It should close SSE connection on closing of event stream when we deploy our application in argoCD. We are able to close SSE event in local machine without using argoCD.

How is http-proxy-middleware used in your project?

const options = {
    target: "{Notification service url}" + "/event/",
    changeOrigin: true,
    logger: console,
    onProxyReq: (proxyReq, req, res) => {
      console.log("On proxy req set custom proxy header")
      res.on('close', () => {
        proxyReq.destroy()
      });
    }
  };

  app.use('/event/*', createProxyMiddleware(options));

What http-proxy-middleware configuration are you using?

const options = {
    target: "{Notification service url}" + "/event/",
    changeOrigin: true,
    logger: console,
    onProxyReq: (proxyReq, req, res) => {
      console.log("On proxy req set custom proxy header")
      res.on('close', () => {
        console.log("On close for proxy res");
        proxyReq.destroy()
      });
    }
  };

What OS/version and node/version are you seeing the problem?

Argo CD: v2.7.2+cbee7e6.dirty  platform: linux/amd64

  node:16-alpine3.16

Additional context (optional)

No response

swapnil-bhalekar avatar Mar 20 '24 06:03 swapnil-bhalekar

Can you try with:

onProxyRes: (proxyRes, req, res) => {
    proxyRes.on('close', () => {
      if (!res.writableEnded) {
        res.destroy();
      }
    });
}

from https://github.com/chimurai/http-proxy-middleware/discussions/765#discussioncomment-2617739

chimurai avatar Apr 03 '24 21:04 chimurai

We have already tried this approach. We are getting this issue when using through nginx . Without nginx its working fine.

swapnil-bhalekar avatar Apr 04 '24 06:04 swapnil-bhalekar

Can you provide a working reproduction of this issue so it can be investigated?

chimurai avatar Apr 10 '24 20:04 chimurai