Code Monkey home page Code Monkey logo

Comments (12)

suchen-sci avatar suchen-sci commented on June 12, 2024

What happens if client --> k8s --> pod[backend]?
The error message seems from backend?

from easegress.

cyrnicolase avatar cyrnicolase commented on June 12, 2024

What happens if client --> k8s --> pod[backend]? The error message seems from backend?

client --> k8s --> pod[backend] works well.

from easegress.

suchen-sci avatar suchen-sci commented on June 12, 2024

Hi, if client --> k8s --> pod[backend] works and client --> easegress --> backend works.
It seems some network problem from easegress to k8s?
But websocketproxy can find the backend and got a status code of 404 (not like a network problem).

Emmm, I guess we can use some tool like wireshark to catch some packets. To see what's the difference between easegresss -> k8s and client -> k8s. If they send the same packet, they should get same result.

Make sure you client is on same server of easegress. You can add this filter to your pipeline to diff the requests from your client and easegress.

kind: RequestAdaptor
name: request-adaptor
header:
  add: 
    X-Easegress: Test

If they send different packets, we can find the problem of easegress.

For the information you have provided, I can't dig more...

from easegress.

xxx7xxxx avatar xxx7xxxx commented on June 12, 2024

Which way does Easegress access K8s? Ingress with node port or cluster IP? In my initial intuition there could be a problem in k8s service-level.

from easegress.

cyrnicolase avatar cyrnicolase commented on June 12, 2024

Which way does Easegress access K8s? Ingress with node port or cluster IP? In my initial intuition there could be a problem in k8s service-level.

We use node port. Before we use apisix works well .

from easegress.

cyrnicolase avatar cyrnicolase commented on June 12, 2024

Hi, if client --> k8s --> pod[backend] works and client --> easegress --> backend works. It seems some network problem from easegress to k8s? But websocketproxy can find the backend and got a status code of 404 (not like a network problem).

Emmm, I guess we can use some tool like wireshark to catch some packets. To see what's the difference between easegresss -> k8s and client -> k8s. If they send the same packet, they should get same result.

Make sure you client is on same server of easegress. You can add this filter to your pipeline to diff the requests from your client and easegress.

kind: RequestAdaptor
name: request-adaptor
header:
  add: 
    X-Easegress: Test

If they send different packets, we can find the problem of easegress.

For the information you have provided, I can't dig more...

I may have identified the issue. When Easegress accesses my k8s cluster, the Ingress fails to retrieve the Host. Consequently, it becomes unable to locale the appropriate service.

I have come across the "x-forwarded-host" header in the program. However, I am unsure about how to utilize it.

from easegress.

suchen-sci avatar suchen-sci commented on June 12, 2024

In easegress websocket proxy, if X-Forwarded-Host is empty, then is will be the host of request.

	const xForwardedHost = "X-Forwarded-Host"
	xfh := req.HTTPHeader().Get(xForwardedHost)
	if xfh == "" && req.Host() != "" {
		opts.HTTPHeader.Set(xForwardedHost, req.Host())
	}

from easegress.

cyrnicolase avatar cyrnicolase commented on June 12, 2024

What approach should I take on my Kubernetes (K8s) side to address this issue?

I have make a test.

client --> easegress --> local nginx --> backend

In the case of a WebSocket request, the host information cannot be obtained on the local Nginx server.

from easegress.

cyrnicolase avatar cyrnicolase commented on June 12, 2024
opts.Host = req.Host()			// add this line for reverse proxy

const xForwardedHost = "X-Forwarded-Host"
xfh := req.HTTPHeader().Get(xForwardedHost)
if xfh == "" && req.Host() != "" {
    opts.HTTPHeader.Set(xForwardedHost, req.Host())
}

After adding this line, the functionality was restored successfully.

from easegress.

cyrnicolase avatar cyrnicolase commented on June 12, 2024

https://github.com/megaease/easegress/blob/main/pkg/filters/proxies/server.go#L32

// Server is a backend proxy server.
type Server struct {
	URL            string   `json:"url" jsonschema:"required,format=url"`
	Tags           []string `json:"tags,omitempty" jsonschema:"uniqueItems=true"`
	Weight         int      `json:"weight,omitempty" jsonschema:"minimum=0,maximum=100"`
	KeepHost       bool     `json:"keepHost,omitempty" jsonschema:"default=false"`
	AddrIsHostName bool     `json:"-"`
	Unhealth       bool     `json:"-"`
	// HealthCounter is used to count the number of successive health checks
	// result, positive for healthy, negative for unhealthy
	HealthCounter int `json:"-"`
}

The KeepHost property is not utilized in the Websocket proxy. I believe we can incorporate it into the Websocket DialOptions struct, similar to HTTP proxy.

https://github.com/megaease/easegress/blob/main/pkg/filters/proxies/httpproxy/wspool.go#L121

	opts := &websocket.DialOptions{
		HTTPHeader:      req.HTTPHeader().Clone(),
		CompressionMode: websocket.CompressionDisabled,
	}


        // only set host when server address is not host name OR
	// server is explicitly told to keep the host of the request.
	if !svr.AddrIsHostName || svr.KeepHost {
		opts.Host = req.Host()
	}

	opts.HTTPHeader.Del("Sec-WebSocket-Origin")
	opts.HTTPHeader.Del("Sec-WebSocket-Protocol")
	opts.HTTPHeader.Del("Sec-WebSocket-Accept")
	opts.HTTPHeader.Del("Sec-WebSocket-Extensions")

Now, it works for me.

from easegress.

suchen-sci avatar suchen-sci commented on June 12, 2024

In the implementation of websocket pkg, it said the host may overrides the host of http. i think that maybe the problem.

	// Host optionally overrides the Host HTTP header to send. If empty, the value
	// of URL.Host will be used.
	Host string

from easegress.

suchen-sci avatar suchen-sci commented on June 12, 2024

Hi, @cyrnicolase , your solution seems great and consistency with Proxy filter. Could you please make a pr about it? Thanks!

from easegress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.