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

fasthttp http2 Whether connection-level health probes are supported #66

Open
zxpdmw opened this issue Sep 26, 2023 · 13 comments
Open

fasthttp http2 Whether connection-level health probes are supported #66

zxpdmw opened this issue Sep 26, 2023 · 13 comments

Comments

@zxpdmw
Copy link

zxpdmw commented Sep 26, 2023

No description provided.

@zxpdmw zxpdmw changed the title fasthttp 合同谈判 fasthttp http2 Whether connection-level health probes are supported Sep 26, 2023
@zxpdmw
Copy link
Author

zxpdmw commented Sep 26, 2023

image
What this does is simulate a network/http2 connection-level health probe

@dgrr
Copy link
Owner

dgrr commented Sep 26, 2023

Hello, as far as I remember the client does ping the server using the PingInterval, but it doesn't close the connection if a number of pings failed. I'd accept a PR for that.
https://github.com/dgrr/http2/blob/master/conn.go#L459

@zxpdmw
Copy link
Author

zxpdmw commented Sep 27, 2023

Why only fasthttp.hostclient support http2

@zxpdmw
Copy link
Author

zxpdmw commented Sep 27, 2023

If the client fails to ping the server for many times, it hopes to close the connection in time, so that the request fails quickly and enters the retry logic

@zxpdmw
Copy link
Author

zxpdmw commented Sep 27, 2023

func (c *Conn) writeLoop() {
	var lastErr error

	defer func() { _ = c.Close() }()

	defer func() {
		if err := recover(); err != nil {
			if lastErr == nil {
				switch errn := err.(type) {
				case error:
					lastErr = errn
				case string:
					lastErr = errors.New(errn)
				}
			}
		}

		if lastErr == nil {
			lastErr = io.ErrUnexpectedEOF
		}

		c.reqQueued.Range(func(_, v interface{}) bool {
			r := v.(*Ctx)
			r.resolve(lastErr)

			return true
		})
	}()

	if c.pingInterval <= 0 {
		c.pingInterval = DefaultPingInterval
	}

	ticker := time.NewTicker(c.pingInterval)
	defer ticker.Stop()

loop:
	for {
		select {
		case ctx, ok := <-c.in: // sending requests
			if !ok {
				break loop
			}

			err := c.writeRequest(ctx)
			if err != nil {
				ctx.resolve(err)

				if errors.Is(err, ErrNotAvailableStreams) {
					continue
				}

				lastErr = WriteError{err}

				break loop
			}
		case fr, ok := <-c.out: // generic output
			if !ok {
				break loop
			}

			err := c.writeFrame(fr)
			if err != nil {
				lastErr = WriteError{err}
				break loop
			}

			ReleaseFrameHeader(fr)
		case <-ticker.C: // ping
			if err := c.writePing(); err != nil {
				lastErr = WriteError{err}
				break loop
			}
		}

		if !c.disableAcks && c.unacks >= 3 {
			lastErr = ErrTimeout
			break loop
		}
	}
}

defer c.Close Won't the connection be closed

		if !c.disableAcks && c.unacks >= 3 {
			lastErr = ErrTimeout
			break loop
		}

If ack is enabled and the number of acks is greater than three times, it will jump out of the loop, and eventually it will execute until the defer closes the connection

@zxpdmw
Copy link
Author

zxpdmw commented Sep 27, 2023

writeLoop AND readLoop The method is all the same logic

@zxpdmw
Copy link
Author

zxpdmw commented Sep 27, 2023

Fasthttp HTTP2 Client looks like the code implementation has implemented connection-level health detection

@dgrr
Copy link
Owner

dgrr commented Sep 27, 2023

Yes, it seems like it. Is your question resolved?

@zxpdmw
Copy link
Author

zxpdmw commented Sep 27, 2023

I use this library, it seems that I am still using http1, and the example in the code log does not run

@dgrr
Copy link
Owner

dgrr commented Sep 27, 2023

Does the server support HTTP/2? Are you connecting through TLS?

@zxpdmw
Copy link
Author

zxpdmw commented Oct 7, 2023

Without using TLS, the example in my repository won't work in http2

@dgrr
Copy link
Owner

dgrr commented Oct 7, 2023

Yes, the library only supports TLS.

@zxpdmw
Copy link
Author

zxpdmw commented Oct 8, 2023

Do the client and server support TLS at the same time?

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

No branches or pull requests

2 participants