gin icon indicating copy to clipboard operation
gin copied to clipboard

experimental: support http3

Open thinkerou opened this issue 3 years ago • 14 comments

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

thinkerou avatar Jun 26 '22 12:06 thinkerou

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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%) :arrow_up:
go-1.21 99.19% <100.00%> (-0.03%) :arrow_down:
go-1.22 99.19% <100.00%> (?)
macos-latest 99.17% <100.00%> (-0.04%) :arrow_down:
ubuntu-latest 99.19% <100.00%> (-0.03%) :arrow_down:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 26 '22 12:06 codecov[bot]

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

hktalent avatar Dec 30 '22 03:12 hktalent

ping @thinkerou

appleboy avatar Jan 01 '23 06:01 appleboy

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

appleboy avatar Apr 26 '23 02:04 appleboy

@thinkerou Can you keep working on this PR?

appleboy avatar Apr 26 '23 03:04 appleboy

@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

thinkerou avatar Apr 26 '23 11:04 thinkerou

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

mcules avatar Aug 21 '23 11:08 mcules

https://endoflife.date/go

1.19 support Ended 2 weeks ago

raphaelauv avatar Aug 24 '23 15:08 raphaelauv

Waiting for https://github.com/golang/go/issues/58547 QUIC implementation

appleboy avatar Jan 05 '24 14:01 appleboy

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 https://github.com/cloudflare/cloudflared/issues/522#issuecomment-1018787568

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 avatar Feb 08 '24 10:02 maggie44

And here with a fixed test example: https://github.com/maggie44/gin/commit/790cfe2ed2e4e94a778d88973fe1414f64b7a779

maggie44 avatar Feb 08 '24 11:02 maggie44

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.

marten-seemann avatar Feb 14 '24 01:02 marten-seemann

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()

bound2 avatar May 05 '24 07:05 bound2

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.

maggie44 avatar May 06 '24 06:05 maggie44

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 avatar May 08 '24 13:05 thinkerou

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

appleboy avatar May 09 '24 00:05 appleboy