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

fix(smb): remount smb before each operation #2140

Merged
merged 1 commit into from
Oct 30, 2022
Merged

Conversation

BoYanZh
Copy link
Member

@BoYanZh BoYanZh commented Oct 28, 2022

Tried solutions:

  1. Use conn.Write to check the connection, but it can not detect some of SMB error.
  2. Use d.fs.Lstat or d.fs.ReadDir to check the connection, but after un-share and re-share, it will raise a panic.
runtime error: invalid memory address or nil pointer dereference

runtime/debug.Stack()
	C:/Program Files/Go/src/runtime/debug/stack.go:24 +0x65
github.com/alist-org/alist/v3/pkg/singleflight.newPanicError({0x7ff6792bd9c0?, 0x7ff6791878a0})
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:35 +0x2c
github.com/alist-org/alist/v3/pkg/singleflight.(*Group[...]).doCall.func2.1()
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:188 +0x3b
panic({0x7ff6792bd9c0, 0x7ff6791878a0})
	C:/Program Files/Go/src/runtime/panic.go:884 +0x212
github.com/hirochachacha/go-smb2.(*Share).loanCredit(...)
	C:/Users/BoYanZh/go/pkg/mod/github.com/hirochachacha/go-smb2@v1.1.0/client.go:1022
github.com/hirochachacha/go-smb2.(*Share).createFileRec(0x0, {0x0, 0x0}, 0xc0002aaa00)
	C:/Users/BoYanZh/go/pkg/mod/github.com/hirochachacha/go-smb2@v1.1.0/client.go:941 +0x9e
github.com/hirochachacha/go-smb2.(*Share).createFile(0x7ff67942fb0d?, {0x0?, 0x0?}, 0xc00063ac88?, 0x5?)
	C:/Users/BoYanZh/go/pkg/mod/github.com/hirochachacha/go-smb2@v1.1.0/client.go:909 +0x2a5
github.com/hirochachacha/go-smb2.(*Share).Stat(0xc000240a10?, {0x7ff67913d3f0?, 0xc00063ace0?})
	C:/Users/BoYanZh/go/pkg/mod/github.com/hirochachacha/go-smb2@v1.1.0/client.go:665 +0xb3
github.com/alist-org/alist/v3/drivers/smb.(*SMB).checkConn(0xc0006cc000)
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/drivers/smb/util.go:41 +0x7b
github.com/alist-org/alist/v3/drivers/smb.(*SMB).List(0xc0006cc000, {0x0?, 0x30002?}, {0x7ff679c33698, 0xc0009faba0}, {{0x8?, 0xb?}})
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/drivers/smb/driver.go:48 +0x46
github.com/alist-org/alist/v3/internal/op.List.func1()
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/internal/op/fs.go:57 +0x68
github.com/alist-org/alist/v3/pkg/singleflight.(*Group[...]).doCall.func2(0xc00063af5e?, 0xc0009fac60, 0x2108dec0a28)
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:193 +0x71
github.com/alist-org/alist/v3/pkg/singleflight.(*Group[...]).doCall(0xc0006ef0e0?, 0xc000632617?, {0xc000632617?, 0xc0006cc000?}, 0xc00063b0c8?)
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:195 +0xb0
github.com/alist-org/alist/v3/pkg/singleflight.(*Group[...]).Do(0x7ff67a41bed0, {0xc000632617, 0x5}, 0xc00063b0c8)
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:108 +0x176
github.com/alist-org/alist/v3/internal/op.List({0x7ff679c30db8, 0xc000636200}, {0x7ff679c38b20, 0xc0006cc000?}, {0x7ff67942d980, 0x1}, {{0xc000632290?, 0x0?}}, {0xc00063b397, 0x1, ...})
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/internal/op/fs.go:56 +0x454
github.com/alist-org/alist/v3/internal/fs.list({0x7ff679c30db8, 0xc000636200}, {0xc000632290, 0x5}, {0xc00063b397, 0x1, 0x1})
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/internal/fs/list.go:27 +0x22e
github.com/alist-org/alist/v3/internal/fs.List({0x7ff679c30db8?, 0xc000636200?}, {0xc000632290, 0x5}, {0xc00063b397?, 0x0?, 0x7ff678a1c3c0?})
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/internal/fs/fs.go:17 +0x45
github.com/alist-org/alist/v3/server/handles.FsList(0xc000240930?)
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/server/handles/fsread.go:77 +0x3d3
github.com/gin-gonic/gin.(*Context).Next(...)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173
github.com/alist-org/alist/v3/server/middlewares.Auth(0xc000636200)
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/server/middlewares/auth.go:55 +0x3d0
github.com/gin-gonic/gin.(*Context).Next(...)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173
github.com/alist-org/alist/v3/server/middlewares.StoragesLoaded(0xc000636200)
	C:/Users/BoYanZh/Documents/Github/alist-org/alist/server/middlewares/check.go:11 +0x6d
github.com/gin-gonic/gin.(*Context).Next(...)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1(0xc000636200)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/recovery.go:101 +0x82
github.com/gin-gonic/gin.(*Context).Next(...)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173
github.com/gin-gonic/gin.LoggerWithConfig.func1(0xc000636200)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/logger.go:240 +0xe7
github.com/gin-gonic/gin.(*Context).Next(...)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000584680, 0xc000636200)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/gin.go:613 +0x671
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000584680, {0x7ff679c2f140?, 0xc0009160e0}, 0xc000636500)
	C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/gin.go:569 +0x1dd
net/http.serverHandler.ServeHTTP({0x7ff679c2a968?}, {0x7ff679c2f140, 0xc0009160e0}, 0xc000636500)
	C:/Program Files/Go/src/net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc000000000, {0x7ff679c30a70, 0xc0005a5a40})
	C:/Program Files/Go/src/net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
	C:/Program Files/Go/src/net/http/server.go:3102 +0x4db

C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:165 (0x7ff678848f49)
	(*Group[...]).doCall.func1: panic(e)
C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:200 (0x7ff67884a36a)
	(*Group[...]).doCall: }
C:/Users/BoYanZh/Documents/Github/alist-org/alist/pkg/singleflight/singleflight.go:108 (0x7ff67884a175)
	(*Group[...]).Do: g.doCall(c, key, fn)
C:/Users/BoYanZh/Documents/Github/alist-org/alist/internal/op/fs.go:56 (0x7ff678842593)
	List: objs, err, _ := listG.Do(key, func() ([]model.Obj, error) {
C:/Users/BoYanZh/Documents/Github/alist-org/alist/internal/fs/list.go:27 (0x7ff678e6682d)
	list: objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
C:/Users/BoYanZh/Documents/Github/alist-org/alist/internal/fs/fs.go:17 (0x7ff678e65244)
	List: res, err := list(ctx, path, refresh...)
C:/Users/BoYanZh/Documents/Github/alist-org/alist/server/handles/fsread.go:77 (0x7ff678e9c812)
	FsList: objs, err := fs.List(c, req.Path, req.Refresh)
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173 (0x7ff678fd67ef)
	(*Context).Next: c.handlers[c.index](c)
C:/Users/BoYanZh/Documents/Github/alist-org/alist/server/middlewares/auth.go:55 (0x7ff678fd6638)
	Auth: c.Next()
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173 (0x7ff678fd6aac)
	(*Context).Next: c.handlers[c.index](c)
C:/Users/BoYanZh/Documents/Github/alist-org/alist/server/middlewares/check.go:11 (0x7ff678fd6a66)
	StoragesLoaded: c.Next()
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173 (0x7ff678b910a1)
	(*Context).Next: c.handlers[c.index](c)
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/recovery.go:101 (0x7ff678b9108c)
	CustomRecoveryWithWriter.func1: c.Next()
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173 (0x7ff678b901a6)
	(*Context).Next: c.handlers[c.index](c)
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/logger.go:240 (0x7ff678b90189)
	LoggerWithConfig.func1: c.Next()
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/context.go:173 (0x7ff678b8f2b0)
	(*Context).Next: c.handlers[c.index](c)
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/gin.go:613 (0x7ff678b8ef18)
	(*Engine).handleHTTPRequest: c.Next()
C:/Users/BoYanZh/go/pkg/mod/github.com/gin-gonic/gin@v1.8.0/gin.go:569 (0x7ff678b8ea5c)
	(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
C:/Program Files/Go/src/net/http/server.go:2947 (0x7ff67869f4cb)
	serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
C:/Program Files/Go/src/net/http/server.go:1991 (0x7ff67869a6e6)
	(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
C:/Program Files/Go/src/runtime/asm_amd64.s:1594 (0x7ff6783ceb00)
	goexit: BYTE	$0x90	// NOP

Maybe context should be used to prevent checking connection for too many times?

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

Successfully merging this pull request may close these issues.

None yet

2 participants