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

feat(gin): support http3 using quic-go/quic-go #3210

Merged
merged 18 commits into from May 9, 2024

Conversation

thinkerou
Copy link
Member

@thinkerou thinkerou commented Jun 26, 2022

but, quic-go supports the min go version is 1.19
and remove go1.15 for compiling successful

@codecov
Copy link

codecov bot commented Jun 26, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.19%. Comparing base (3dc1cd6) to head (be70e87).
Report is 49 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3210      +/-   ##
==========================================
- Coverage   99.21%   99.19%   -0.03%     
==========================================
  Files          42       43       +1     
  Lines        3182     2722     -460     
==========================================
- Hits         3157     2700     -457     
+ Misses         17       12       -5     
- Partials        8       10       +2     
Flag Coverage Δ
?
-tags "sonic avx" 99.18% <100.00%> (?)
-tags go_json 99.18% <100.00%> (?)
-tags nomsgpack 99.17% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 100.00% <ø> (+0.78%) ⬆️
go-1.21 99.19% <100.00%> (-0.03%) ⬇️
go-1.22 99.19% <100.00%> (?)
macos-latest 99.17% <100.00%> (-0.04%) ⬇️
ubuntu-latest 99.19% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hktalent
Copy link
Contributor

don't use http3.ListenAndServeQUIC
example

h3s := http3.Server{
			Addr:       addr,
			Handler:    router.Handler(),
			TLSConfig:  util1.GTls,
			QuicConfig: &quic.Config{},
		}
		if err := h3s.ListenAndServe(); nil != err {
			log.Println("HTTP/3.0 ListenAndServe ", err)
		} else {
			log.Printf("HTTP/3.0  Listening and serving HTTPS on %s\n", addr)
		}

Util1.GTls will be obtained from the dynamic ca server challenge

@appleboy
Copy link
Member

appleboy commented Jan 1, 2023

ping @thinkerou

@thinkerou thinkerou added this to the v1.10 milestone Jan 17, 2023
@appleboy
Copy link
Member

New repo: https://github.com/quic-go/quic-go

@appleboy
Copy link
Member

@thinkerou Can you keep working on this PR?

@thinkerou
Copy link
Member Author

@thinkerou Can you keep working on this PR?

updated, but have unit test error:

=== RUN   TestRunQUIC
2023/04/26 07:24:50 failed to sufficiently increase receive buffer size (was: 208 kiB, wanted: 2048 kiB, got: 416 kiB). See https://github.com/quic-go/quic-go/wiki/UDP-Receive-Buffer-Size for details.
    gin_integration_test.go:43: 
        	Error Trace:	/home/runner/work/gin/gin/gin_integration_test.go:43
        	            				/home/runner/work/gin/gin/gin_integration_1.19_test.go:30
        	Error:      	Received unexpected error:
        	            	Get "https://localhost:8443/example": dial tcp [::1]:8443: connect: connection refused
        	Test:       	TestRunQUIC
--- FAIL: TestRunQUIC (0.01s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0xa8aae2]

goroutine 193 [running]:
testing.tRunner.func1.2({0xb4a9e0, 0x11b7ea0})
	/opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
	/opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1399 +0x39f
panic({0xb4a9e0, 0x11b7ea0})
	/opt/hostedtoolcache/go/1.19.8/x64/src/runtime/panic.go:884 +0x212
github.com/gin-gonic/gin.testRequest(0xc0004af520, {0xc0000c9f50, 0x1, 0xc00040a050?})
	/home/runner/work/gin/gin/gin_integration_test.go:44 +0x182
github.com/gin-gonic/gin.TestRunQUIC(0xc0004af520)
	/home/runner/work/gin/gin/gin_integration_1.19_test.go:30 +0x108
testing.tRunner(0xc0004af520, 0xc6df88)
	/opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
	/opt/hostedtoolcache/go/1.19.8/x64/src/testing/testing.go:1493 +0x35f
FAIL	github.com/gin-gonic/gin	0.084s
FAIL

https://github.com/gin-gonic/gin/actions/runs/4806024121/jobs/8553052446?pr=3210

@mcules
Copy link

mcules commented Aug 21, 2023

@thinkerou is there a running version for current stable and an example?

@raphaelauv
Copy link

https://endoflife.date/go

1.19 support Ended 2 weeks ago

@appleboy
Copy link
Member

appleboy commented Jan 5, 2024

Waiting for golang/go#58547 QUIC implementation

@appleboy appleboy closed this Jan 5, 2024
@maggie44
Copy link

maggie44 commented Feb 8, 2024

failed to sufficiently increase receive buffer size

This error is anticipated and isn't blocking. Here is the info about it from Cloudflared where it has been used in production for a number of years:

https://github.com/quic-go/quic-go/wiki/UDP-Buffer-Sizes
cloudflare/cloudflared#522 (comment)

Duly noted on Golang official implementation, adding in the info here though for reference. Will subscribe to the tracking issue and lend a hand when the time is right.

@maggie44
Copy link

maggie44 commented Feb 8, 2024

And here with a fixed test example: maggie44@790cfe2

@appleboy appleboy reopened this Feb 13, 2024
@marten-seemann
Copy link

but, quic-go supports the min go version is 1.19 and remove go1.15 for compiling successful

Since mid 2023, quic-go is using crypto/tls (since crypto/tls gained QUIC support in Go 1.20), and we don't impose any limitations on Go versions anymore. This PR should probably be updated to use a more recent quic-go version.

@appleboy appleboy modified the milestones: v1.10, v1.11 Mar 21, 2024
@bound2
Copy link

bound2 commented May 5, 2024

Is there any necessity to make these changes? It works fine when you just provide Gin router handler to quic-go.

Versions used

go 1.21
github.com/gin-gonic/gin v1.9.1
github.com/quic-go/quic-go v0.43.1

Example code

	r := gin.Default()
	r.GET("/health/liveness", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"status": "UP",
		})
	})

	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		addr := ":8443"
		err = http3.ListenAndServe(addr, certFileName, keyFileName, r.Handler())
		if err != nil {
			log.Printf(err.Error())
		}
		wg.Done()
	}()
	wg.Wait()

@maggie44
Copy link

maggie44 commented May 6, 2024

Is there any necessity to make these changes? It works fine when you just provide Gin router handler to quic-go.

Versions used

go 1.21
github.com/gin-gonic/gin v1.9.1
github.com/quic-go/quic-go v0.43.1

Example code

	r := gin.Default()
	r.GET("/health/liveness", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"status": "UP",
		})
	})

	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		addr := ":8443"
		err = http3.ListenAndServe(addr, certFileName, keyFileName, r.Handler())
		if err != nil {
			log.Printf(err.Error())
		}
		wg.Done()
	}()
	wg.Wait()

The idea is to add a r.RunQUIC() like there is a r.Run().

https://gin-gonic.com/docs/quickstart/

But like r.Run() it’s not necessary to use it.

@thinkerou
Copy link
Member Author

new error:

Run golangci/golangci-lint-action@v5
prepare environment
run golangci-lint
  Running [/home/runner/golangci-lint-1.56.2-linux-amd64/golangci-lint run --out-format=github-actions --verbose] in [/home/runner/work/gin/gin] ...
  level=info msg="[config_reader] Config search paths: [./ /home/runner/work/gin/gin /home/runner/work/gin /home/runner/work /home/runner /home /]"
  level=info msg="[config_reader] Used config file .golangci.yml"
  level=info msg="[lintersdb] Active 21 linters: [asciicheck dogsled durationcheck errcheck errorlint exportloopref gci gofmt goimports gosec gosimple govet ineffassign misspell nakedret nilerr nolintlint revive staticcheck unused wastedassign]"
  level=info msg="[loader] Go packages loading at mode 575 (files|compiled_files|deps|name|types_sizes|exports_file|imports) took 21.776580317s"
  level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 18.405646ms"
  level=info msg="[linters_context/goanalysis] analyzers took 8.109568909s with top 10 stages: the_only_name: 2.467771309s, buildir: 829.483659ms, wastedassign: 536.82[26](https://github.com/gin-gonic/gin/actions/runs/9002034491/job/24729483450?pr=3210#step:4:28)4ms, buildssa: 464.54057ms, S1038: 307.837725ms, goimports: 290.298783ms, gci: 280.586263ms, errorlint: 258.377102ms, unused: 231.489601ms, misspell: 205.949709ms"
  level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package utils: could not load export data: no export data for \"github.com/quic-go/quic-go/internal/utils\""
  level=info msg="[runner] processing took 2.955µs with stages: max_same_issues: 491ns, skip_dirs: 371ns, nolint: 360ns, path_prettifier: 201ns, cgo: 181ns, identifier_marker: 150ns, exclude-rules: 150ns, source_code: 150ns, filename_unadjuster: 141ns, max_from_linter: 140ns, autogenerated_exclude: 130ns, path_prefixer: 51ns, path_shortener: 50ns, fixer: 50ns, sort_results: 50ns, max_per_file_from_linter: 50ns, diff: 50ns, uniq_by_line: 50ns, exclude: 50ns, skip_files: 49ns, severity-rules: 40ns"
  level=info msg="[runner] linters took 1.30[27](https://github.com/gin-gonic/gin/actions/runs/9002034491/job/24729483450?pr=3210#step:4:29)10887s with stages: goanalysis_metalinter: 1.302668949s"
  level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package utils: could not load export data: no export data for \"github.com/quic-go/quic-go/internal/utils\""
  level=info msg="Memory: 233 samples, avg is 35.2MB, max is 231.6MB"
  level=info msg="Execution took 23.10310595s"
  
  Error: golangci-lint exit with code 3
  Ran golangci-lint in 23199ms

@thinkerou thinkerou closed this May 8, 2024
@thinkerou thinkerou reopened this May 8, 2024
- Remove dynamic Go versioning in favor of pinning to major version `1`
- Update linter version from `v1.56.2` to `v1.58.1` in GitHub Actions workflow

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Update the golangci-lint-action version from `v5` to `v6` in the GitHub workflow configuration

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Update Go version requirement from `1.20` to `1.21` in `go.mod`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@appleboy appleboy changed the title experimental: support http3 feat(gin): support http3 using quic-go/quic-go May 9, 2024
@appleboy
Copy link
Member

appleboy commented May 9, 2024

since the quic-go/quic-go only support go v1.21 version, I upgrade the go.mod to 1.21 version.

https://github.com/quic-go/quic-go/blob/d1c1f18e4c707d26f038698c9f67d77ec85a14a5/go.mod#L3

- Add an empty line in the import section of `gin.go`

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
- Add `gin.go` to the list of files with specific linters in `.golangci.yml`, applying the `gci` linter.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@appleboy appleboy merged commit 3ac729d into gin-gonic:master May 9, 2024
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants