codeskyblue / codeskyblue/gohttpserver

Error fetching large folders

Open
#117 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
2.8k
Forks
583
PR merge metrics
No merged PRs in 30d

Description

### Description
I'm getting the following error when fetching large folders or trying to delete more than one folder at a time:

```
fatal error: concurrent map writes

goroutine 448 [running]:
runtime.throw(0x98b18d, 0x15)
/usr/local/go/src/runtime/panic.go:1117 +0x72 fp=0xc00058cf50 sp=0xc00058cf20 pc=0x4362d2
runtime.mapassign_faststr(0x8f69a0, 0xc09ba86c90, 0xc000340730, 0x46, 0xd275c0)
/usr/local/go/src/runtime/map_faststr.go:291 +0x3d8 fp=0xc00058cfb8 sp=0xc00058cf50 pc=0x4143f8
main.(*HTTPStaticServer).historyDirSize(0xc0000f4000, 0xc000340730, 0x46, 0xc000340730)
/app/gohttpserver/httpstaticserver.go:667 +0xea fp=0xc00058d028 sp=0xc00058cfb8 pc=0x888bca
main.(*HTTPStaticServer).hJSONList(0xc0000f4000, 0xa297e0, 0xc002772210, 0xc002c96600)
/app/gohttpserver/httpstaticserver.go:617 +0x6a5 fp=0xc00058d478 sp=0xc00058d028 pc=0x888065
main.(*HTTPStaticServer).hIndex(0xc0000f4000, 0xa297e0, 0xc002772210, 0xc002c96600)
/app/gohttpserver/httpstaticserver.go:126 +0x7d5 fp=0xc00058d5c0 sp=0xc00058d478 pc=0x884415
main.(*HTTPStaticServer).hIndex-fm(0xa297e0, 0xc002772210, 0xc002c96600)
/app/gohttpserver/httpstaticserver.go:122 +0x51 fp=0xc00058d5f0 sp=0xc00058d5c0 pc=0x893271
net/http.HandlerFunc.ServeHTTP(0xc0000717a0, 0xa297e0, 0xc002772210, 0xc002c96600)
/usr/local/go/src/net/http/server.go:2069 +0x44 fp=0xc00058d618 sp=0xc00058d5f0 pc=0x6be044
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0000a4380, 0xa297e0, 0xc002772210, 0xc002c96400)
/go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162 +0x106 fp=0xc00058d770 sp=0xc00058d618 pc=0x7992c6
main.(*HTTPStaticServer).ServeHTTP(0xc0000f4000, 0xa297e0, 0xc002772210, 0xc002c96400)
/app/gohttpserver/httpstaticserver.go:104 +0x50 fp=0xc00058d7a0 sp=0xc00058d770 pc=0x883a70
github.com/codeskyblue/go-accesslog.(*LoggingHandler).ServeHTTP(0xc0000e0a50, 0xa29cf0, 0xc0109f20e0, 0xc002c96400)
/go/pkg/mod/github.com/codeskyblue/go-accesslog@v0.0.0-20171215023101-6188d3bd9371/accesslog.go:162 +0x3db fp=0xc00058da18 sp=0xc00058d7a0 pc=0x84599b
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0000fe070, 0xa29cf0, 0xc0109f20e0, 0xc002c96000)
/go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162 +0x106 fp=0xc00058db70 sp=0xc00058da18 pc=0x7992c6
net/http.serverHandler.ServeHTTP(0xc0000fc2a0, 0xa29cf0, 0xc0109f20e0, 0xc002c96000)
/usr/local/go/src/net/http/server.go:2887 +0xa3 fp=0xc00058dba0 sp=0xc00058db70 pc=0x6c1703
net/http.(*conn).serve(0xc010d308c0, 0xa2ae60, 0xc0035e41c0)
/usr/local/go/src/net/http/server.go:1952 +0x8cd fp=0xc00058dfc8 sp=0xc00058dba0 pc=0x6bcb2d
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc00058dfd0 sp=0xc00058dfc8 pc=0x46b841
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3013 +0x39b

goroutine 1 [IO wait]:
internal/poll.runtime_pollWait(0x7f21278fe898, 0x72, 0x0)
/usr/local/go/src/runtime/netpoll.go:222 +0x55
internal/poll.(*pollDesc).wait(0xc00002c798, 0x72, 0x0, 0x0, 0x981f74)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
internal/poll.(*pollDesc).waitRead(...)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Accept(0xc00002c780, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:401 +0x212
net.(*netFD).accept(0xc00002c780, 0x96c6c79de6c42a5, 0x0, 0x0)
/usr/local/go/src/net/fd_unix.go:172 +0x45
net.(*TCPListener).accept(0xc00000c618, 0x60daebaf, 0xc00006bc18, 0x48a506)
/usr/local/go/src/net/tcpsock_posix.go:139 +0x32
net.(*TCPListener).Accept(0xc00000c618, 0xc00006bc68, 0x18, 0xc000000180, 0x6c1bfb)
/usr/local/go/src/net/tcpsock.go:261 +0x65
net/http.(*Server).Serve(0xc0000fc2a0, 0xa29ae0, 0xc00000c618, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:2981 +0x285
net/http.(*Server).ListenAndServe(0xc0000fc2a0, 0xc0000fc2a0, 0xc000209f00)
/usr/local/go/src/net/http/server.go:2910 +0xba
main.main()
/app/gohttpserver/main.go:256 +0x805

goroutine 6 [sleep, 8 minutes]:
time.Sleep(0x8bb2c97000)
/usr/local/go/src/runtime/time.go:193 +0xd2
main.NewHTTPStaticServer.func2(0xc0000f4000)
/app/gohttpserver/httpstaticserver.go:89 +0x139
created by main.NewHTTPStaticServer
/app/gohttpserver/httpstaticserver.go:81 +0x1d7

goroutine 631 [IO wait]:
internal/poll.runtime_pollWait(0x7f21278fe070, 0x72, 0xffffffffffffffff)
/usr/local/go/src/runtime/netpoll.go:222 +0x55
internal/poll.(*pollDesc).wait(0xc00002c498, 0x72, 0x1000, 0x1000, 0xffffffffffffffff)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
internal/poll.(*pollDesc).waitRead(...)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc00002c480, 0xc0002a7000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:166 +0x1d5
net.(*netFD).Read(0xc00002c480, 0xc0002a7000, 0x1000, 0x1000, 0x0, 0x40, 0xc0001fd790)
/usr/local/go/src/net/fd_posix.go:55 +0x4f
net.(*conn).Read(0xc09b3e8088, 0xc0002a7000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:183 +0x91
net/http.(*connReader).Read(0xc00c2daf00, 0xc0002a7000, 0x1000, 0x1000, 0x8, 0x97ec7c, 0x1)
/usr/local/go/src/net/http/server.go:800 +0x1b9
bufio.(*Reader).fill(0xc00007f320)
/usr/local/go/src/bufio/bufio.go:101 +0x108
bufio.(*Reader).ReadSlice(0xc00007f320, 0xc00a7c420a, 0xc, 0xc01428e640, 0x3, 0xc01428e644, 0x29)
/usr/local/go/src/bufio/bufio.go:360 +0x3d
bufio.(*Reader).ReadLine(0xc00007f320, 0x20300a, 0x20300a, 0x1, 0xa14c60, 0x0, 0xc0001fd8b8)
/usr/local/go/src/bufio/bufio.go:389 +0x34
net/textproto.(*Reader).readLineSlice(0xc003a3c120, 0xc0298df300, 0xc0001fd9e8, 0x4e6833, 0xc00002c480, 0x438ffc)
/usr/local/go/src/net/textproto/reader.go:57 +0xd6
net/textproto.(*Reader).ReadLine(...)
/usr/local/go/src/net/textproto/reader.go:38
net/http.readRequest(0xc00007f320, 0x0, 0xc0298df300, 0x0, 0x0)
/usr/local/go/src/net/http/request.go:1027 +0xaa
net/http.(*conn).readRequest(0xc010d30820, 0xa2adb8, 0xc008aaa600, 0x0, 0x0, 0x0)
/usr/local/go/src/net/http/server.go:986 +0x19d
net/http.(*conn).serve(0xc010d30820, 0xa2ae60, 0xc008aaa600)
/usr/local/go/src/net/http/server.go:1878 +0x705
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3013 +0x39b

goroutine 673 [IO wait]:
internal/poll.runtime_pollWait(0x7f21278fe410, 0x72, 0xffffffffffffffff)
/usr/local/go/src/runtime/netpoll.go:222 +0x55
internal/poll.(*pollDesc).wait(0xc00002c198, 0x72, 0x0, 0x1, 0xffffffffffffffff)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
internal/poll.(*pollDesc).waitRead(...)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc00002c180, 0xc0035fa251, 0x1, 0x1, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:166 +0x1d5
net.(*netFD).Read(0xc00002c180, 0xc0035fa251, 0x1, 0x1, 0xc0005aa720, 0x0, 0xc0a0f7e4d8)
/usr/local/go/src/net/fd_posix.go:55 +0x4f
net.(*conn).Read(0xc09b3e8000, 0xc0035fa251, 0x1, 0x1, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:183 +0x91
net/http.(*connReader).backgroundRead(0xc0035fa240)
/usr/local/go/src/net/http/server.go:692 +0x58
created by net/http.(*connReader).startBackgroundRead
/usr/local/go/src/net/http/server.go:688 +0xd5

goroutine 633 [IO wait]:
internal/poll.runtime_pollWait(0x7f21278fdb00, 0x72, 0xffffffffffffffff)
/usr/local/go/src/runtime/netpoll.go:222 +0x55
internal/poll.(*pollDesc).wait(0xc0483dc198, 0x72, 0x0, 0x1, 0xffffffffffffffff)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
internal/poll.(*pollDesc).waitRead(...)
/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc0483dc180, 0xc004018191, 0x1, 0x1, 0x0, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:166 +0x1d5
net.(*netFD).Read(0xc0483dc180, 0xc004018191, 0x1, 0x1, 0xc010d434a0, 0x0, 0xc0a020e6d8)
/usr/local/go/src/net/fd_posix.go:55 +0x4f
net.(*conn).Read(0xc05bc0c040, 0xc004018191, 0x1, 0x1, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:183 +0x91
net/http.(*connReader).backgroundRead(0xc004018180)
/usr/local/go/src/net/http/server.go:692 +0x58
created by net/http.(*connReader).startBackgroundRead
/usr/local/go/src/net/http/server.go:688 +0xd5

goroutine 632 [runnable]:
syscall.Syscall(0x3, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/syscall/asm_linux_amd64.s:20 +0x5
syscall.Close(0xa, 0xc00007e780, 0x0)
/usr/local/go/src/syscall/zsyscall_linux_amd64.go:285 +0x45
internal/poll.(*FD).destroy(0xc00007e780, 0xc03a324000, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:83 +0x43
internal/poll.(*FD).decref(0xc00007e780, 0xc0001f6e01, 0x4eb5d1)
/usr/local/go/src/internal/poll/fd_mutex.go:213 +0x5d
internal/poll.(*FD).Close(0xc00007e780, 0x0, 0x0)
/usr/local/go/src/internal/poll/fd_unix.go:106 +0x4f
os.(*file).close(0xc00007e780, 0xffffffffffffffff, 0xc01408a000)
/usr/local/go/src/os/file_unix.go:251 +0x38
os.(*File).Close(...)
/usr/local/go/src/os/file_posix.go:25
io/ioutil.ReadDir(0xc00002a050, 0x4d, 0x2, 0xc00002a050, 0x4d, 0x0, 0x0)
/usr/local/go/src/io/ioutil/ioutil.go:64 +0x1e5
main.deepPath(0xc010be93e0, 0x21, 0xc00db7a000, 0x2b, 0x30, 0x1a)
/app/gohttpserver/httpstaticserver.go:736 +0x15d
main.(*HTTPStaticServer).hJSONList(0xc0000f4000, 0xa297e0, 0xc003cfc210, 0xc0a1a34600)
/app/gohttpserver/httpstaticserver.go:613 +0x5a5
main.(*HTTPStaticServer).hIndex(0xc0000f4000, 0xa297e0, 0xc003cfc210, 0xc0a1a34600)
/app/gohttpserver/httpstaticserver.go:126 +0x7d5
net/http.HandlerFunc.ServeHTTP(0xc0000717a0, 0xa297e0, 0xc003cfc210, 0xc0a1a34600)
/usr/local/go/src/net/http/server.go:2069 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0000a4380, 0xa297e0, 0xc003cfc210, 0xc0a1a34400)
/go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162 +0x106
main.(*HTTPStaticServer).ServeHTTP(0xc0000f4000, 0xa297e0, 0xc003cfc210, 0xc0a1a34400)
/app/gohttpserver/httpstaticserver.go:104 +0x50
github.com/codeskyblue/go-accesslog.(*LoggingHandler).ServeHTTP(0xc0000e0a50, 0xa29cf0, 0xc010de0620, 0xc0a1a34400)
/go/pkg/mod/github.com/codeskyblue/go-accesslog@v0.0.0-20171215023101-6188d3bd9371/accesslog.go:162 +0x3db
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0000fe070, 0xa29cf0, 0xc010de0620, 0xc0a1a34100)
/go/pkg/mod/github.com/gorilla/mux@v1.6.2/mux.go:162 +0x106
net/http.serverHandler.ServeHTTP(0xc0000fc2a0, 0xa29cf0, 0xc010de0620, 0xc0a1a34100)
/usr/local/go/src/net/http/server.go:2887 +0xa3
net/http.(*conn).serve(0xc0a483e280, 0xa2ae60, 0xc008aaa280)
/usr/local/go/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3013 +0x39b
```

Can you help me out with this, please?

Thanks in advance.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in httpstaticserver.go at historyDirSize around line 667, where the stack trace reports the concurrent map write, then read its caller hJSONList around line 617. Reproduce fetching a large folder or deleting multiple folders and trace the concurrent accesses. Done means these operations no longer trigger the reported panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.