go-swagger build error workaround (docker/ubuntu 20.04)
I've tried to build Stork demo on Ubuntu 20.04. And ended with this error:
rake docker_up
[...]
/repo/build-root/tools/v0.23.0/swagger_linux_amd64 generate server -s server/gen/restapi -m server/gen/models --name Stork --exclude-main --spec /repo/build-root/api/swagger.yaml --template stratoscale --regenerate-configureapi
2020/06/18 19:11:51 loading contrib stratoscale
2020/06/18 19:11:51 added contributed template client/client.gotmpl from templates/contrib/stratoscale/client/client.gotmpl
2020/06/18 19:11:51 added contributed template client/facade.gotmpl from templates/contrib/stratoscale/client/facade.gotmpl
2020/06/18 19:11:51 added contributed template server/configureapi.gotmpl from templates/contrib/stratoscale/server/configureapi.gotmpl
2020/06/18 19:11:51 added contributed template server/server.gotmpl from templates/contrib/stratoscale/server/server.gotmpl
runtime: mlock of signal stack failed: 12
runtime: increase the mlock limit (ulimit -l) or
runtime: update your kernel to 5.3.15+, 5.4.2+, or 5.5+
fatal error: mlock failed
runtime stack:
runtime.throw(0xd2780f, 0xc)
/usr/local/go/src/runtime/panic.go:1112 +0x72
runtime.mlockGsignal(0xc000603e00)
/usr/local/go/src/runtime/os_linux_x86.go:72 +0x107
runtime.mpreinit(0xc000588a80)
/usr/local/go/src/runtime/os_linux.go:341 +0x78
runtime.mcommoninit(0xc000588a80)
/usr/local/go/src/runtime/proc.go:630 +0x108
runtime.allocm(0xc000061800, 0xd6dda8, 0x0)
/usr/local/go/src/runtime/proc.go:1390 +0x14e
runtime.newm(0xd6dda8, 0xc000061800)
/usr/local/go/src/runtime/proc.go:1704 +0x39
runtime.startm(0x0, 0xc000510301)
/usr/local/go/src/runtime/proc.go:1869 +0x12a
runtime.wakep(...)
/usr/local/go/src/runtime/proc.go:1953
runtime.resetspinning()
/usr/local/go/src/runtime/proc.go:2415 +0x93
runtime.schedule()
/usr/local/go/src/runtime/proc.go:2527 +0x2de
runtime.park_m(0xc000001980)
/usr/local/go/src/runtime/proc.go:2690 +0x9d
runtime.mcall(0x0)
/usr/local/go/src/runtime/asm_amd64.s:318 +0x5b
goroutine 1 [runnable]:
github.com/go-openapi/swag.WriteJSON(0xbefca0, 0xc000be60e0, 0x4, 0x10, 0x0, 0x0, 0x0)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/json.go:56 +0x1ef
github.com/go-openapi/swag.JSONMapItem.MarshalEasyJSON(0xc00089bc7c, 0x4, 0xbefca0, 0xc000be60e0, 0xc000c00620)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:125 +0x6e
github.com/go-openapi/swag.JSONMapSlice.MarshalEasyJSON(0xc000be8000, 0x6, 0x6, 0xc000c00620)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:75 +0x97
github.com/go-openapi/swag.WriteJSON(0xc48420, 0xc000be62c0, 0x3, 0x556a7c, 0x50, 0x68, 0xc000c005b0)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/json.go:59 +0x92
github.com/go-openapi/swag.JSONMapItem.MarshalEasyJSON(0xc00089bc2b, 0x3, 0xc48420, 0xc000be62c0, 0xc000c005b0)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:125 +0x6e
github.com/go-openapi/swag.JSONMapSlice.MarshalEasyJSON(0xc000be60c0, 0x1, 0x1, 0xc000c005b0)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:75 +0x97
github.com/go-openapi/swag.WriteJSON(0xc48420, 0xc000be62e0, 0x7, 0x236, 0x0, 0x0, 0x0)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/json.go:59 +0x92
github.com/go-openapi/swag.JSONMapItem.MarshalEasyJSON(0xc00089bc24, 0x7, 0xc48420, 0xc000be62e0, 0xc000bb0e00)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:125 +0x6e
github.com/go-openapi/swag.JSONMapSlice.MarshalEasyJSON(0xc0001c4780, 0x14, 0x14, 0xc000bb0e00)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:75 +0x97
github.com/go-openapi/swag.WriteJSON(0xc48420, 0xc000bec340, 0x5, 0x80, 0x0, 0x0, 0x0)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/json.go:59 +0x92
github.com/go-openapi/swag.JSONMapItem.MarshalEasyJSON(0xc00089b2b6, 0x5, 0xc48420, 0xc000bec340, 0xc000bb0c40)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:125 +0x6e
github.com/go-openapi/swag.JSONMapSlice.MarshalEasyJSON(0xc0001d4280, 0xa, 0xa, 0xc000bb0c40)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:75 +0x97
github.com/go-openapi/swag.WriteJSON(0xc48420, 0xc000bf01a0, 0xc48420, 0xc000bf01a0, 0x0, 0x0, 0x0)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/json.go:59 +0x92
github.com/go-openapi/swag.YAMLToJSON(0xc15fe0, 0xc000be1020, 0xc15fe0, 0xc000be1020, 0x0, 0x0, 0x5)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:40 +0x85
github.com/go-openapi/swag.YAMLDoc(0x7fffdebefe13, 0x21, 0xc000149d01, 0x0, 0x0, 0xc000787980, 0x4ffd00)
/go/pkg/mod/github.com/go-openapi/swag@v0.19.8/yaml.go:230 +0x60
github.com/go-openapi/loads.Spec(0x7fffdebefe13, 0x21, 0xd49261, 0xc000787a08, 0x1d)
/go/pkg/mod/github.com/go-openapi/loads@v0.19.5/spec.go:123 +0xec
github.com/go-swagger/go-swagger/generator.(*GenOpts).validateAndFlattenSpec(0xc000638fc0, 0x7fffdebefe40, 0xb, 0x0)
/go/src/github.com/go-swagger/go-swagger/generator/spec.go:22 +0x50
github.com/go-swagger/go-swagger/generator.(*GenOpts).analyzeSpec(0xc000638fc0, 0x0, 0x0, 0x7f73563f87d0, 0x0)
/go/src/github.com/go-swagger/go-swagger/generator/spec.go:88 +0x35
github.com/go-swagger/go-swagger/generator.newAppGenerator(0x7fffdebefdf7, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000638fc0, 0xc00001c540, ...)
/go/src/github.com/go-swagger/go-swagger/generator/support.go:61 +0x88
github.com/go-swagger/go-swagger/generator.GenerateServer(0x7fffdebefdf7, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000638fc0, 0xc000638fc0, ...)
/go/src/github.com/go-swagger/go-swagger/generator/support.go:36 +0x94
github.com/go-swagger/go-swagger/cmd/swagger/commands/generate.(*Server).generate(0xc00000a5a0, 0xc000638fc0, 0x0, 0x0)
/go/src/github.com/go-swagger/go-swagger/cmd/swagger/commands/generate/server.go:88 +0x94
github.com/go-swagger/go-swagger/cmd/swagger/commands/generate.createSwagger(0xea6e40, 0xc00000a5a0, 0x8b4a01, 0x7f732f76b2b8)
/go/src/github.com/go-swagger/go-swagger/cmd/swagger/commands/generate/shared.go:175 +0x225
github.com/go-swagger/go-swagger/cmd/swagger/commands/generate.(*Server).Execute(0xc00000a5a0, 0xc0001b4a80, 0x0, 0xe, 0xc00000a5a0, 0x1)
/go/src/github.com/go-swagger/go-swagger/cmd/swagger/commands/generate/server.go:115 +0x37
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc000185e00, 0xc00018c010, 0xe, 0xe, 0x10, 0xd54c3a, 0x2a, 0xbda6e0, 0xc0003b1ef0)
/go/pkg/mod/github.com/jessevdk/go-flags@v1.4.0/parser.go:316 +0x8c0
github.com/jessevdk/go-flags.(*Parser).Parse(...)
/go/pkg/mod/github.com/jessevdk/go-flags@v1.4.0/parser.go:186
main.main()
/go/src/github.com/go-swagger/go-swagger/cmd/swagger/swagger.go:145 +0xafc
rake aborted!
Command failed with status (2): [/repo/build-root/tools/v0.23.0/swagger_lin...]
/repo/build-root/Rakefile:195:in `block (2 levels) in <top (required)>'
/repo/build-root/Rakefile:194:in `chdir'
/repo/build-root/Rakefile:194:in `block in <top (required)>'
Tasks: TOP => install_server => build_server => gen_server => /repo/build-root/backend/server/gen/restapi/configure_stork.go
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [cd ./build-root && GOPATH=/repo/build-root...]
/repo/Rakefile:551:in `block in <top (required)>'
Tasks: TOP => build_all_copy_in_subdir
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [docker run -v $PWD:/repo --rm stork-builde...]
/home/thomson/devel/stork/Rakefile:544:in `block in <top (required)>'
/usr/share/rubygems-integration/all/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => docker_up => build_all_in_container
(See full trace by running task with --trace)
This is actually a kernel bug, details go#35777 and go#37436. This was so common that go added an actual test to detect if the kernel is buggy on not, that's why it prints this:
runtime: mlock of signal stack failed: 12
runtime: increase the mlock limit (ulimit -l) or
runtime: update your kernel to 5.3.15+, 5.4.2+, or 5.5+
This works fine when building natively, but fails in Docker containers. This ticket proposes a workaround for this problem. It is intended to be temporary (couple months). However, at this time there is no newer kernel available for Ubuntu 20.04 (the lastest as of today) and we can't realistically expect people to compile new kernel for Stork compilation.
Edited by Tomek Mrugalski