Haunting EPIPE errors

Đang mở
#1,677 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, node.js
Lĩnh vực
backend, networking

Hướng nghiên cứu

Bắt đầu trong web-incoming.js, đặc biệt là phần xử lý socket của proxyReq và các phương thức _write và _writev của nó. Tái hiện phản hồi 401 của HAProxy với phần thân POST lớn và quan sát đường đi EPIPE. Hoàn tất khi lỗi từ upstream có thể đến được client mà không khiến instance node-http-proxy tắt hoặc thỉnh thoảng trả về phản hồi rỗng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Hello, I have node-http-proxy proxying HTTP POST requests with big payload (MBs) to upstream haproxy which upon 401 (Unauthorized) error responds early without reading the body and closes connection. This causes EPIPE error in node-http-proxy, no response is returned to the client and the whole node-http-proxy instance shuts down. I need to return the error from haproxy to the client.

I'm trying to ignore EPIPE errors by monkey-patching _write and _writev methods on proxyReq socket in web-incoming.js

...
    // Enable developers to modify the proxyReq before headers are sent
    proxyReq.on('socket', function(socket) {
      const socketWriteOrig = socket._write;
      socket._write = (data, encoding, callback) => {
        return socketWriteOrig.call(socket, data, encoding, (err) => {
          if(err && err.code == 'EPIPE') {
            if(callback) callback();
            return;
          }
          if(callback) callback(err); else throw err;
        });
      }
      const socketWritevOrig = socket._writev;
      socket._writev = (data, callback) => {
        return socketWritevOrig.call(socket, data, (err) => {
          if(err && err.code == 'EPIPE') {
            if(callback) callback();
            return;
          }
          if(callback) callback(err); else throw err;
        });
      }
      if(server && !proxyReq.getHeader('expect')) {
        server.emit('proxyReq', proxyReq, req, res, options);
      }
    });
...

This "patch" improves the behaviour of node-http-proxy a lot, but still I occasionally get empty response.

Any ideas how to handle EPIPE correctly or improve my "monkey-patch"?

Here is my node-http-proxy instance:

httpProxy
  .createProxyServer({target:'http://localhost:8008',xfwd:false,ws:true})
  .listen(8007);
Ngôn ngữ chính
JavaScript
Star
14.1k
Fork
2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của http-party/node-http-proxy

Tất cả issue của http-party/node-http-proxy

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.