Repository: AlistGo/alist (language: go)

Issue:
[data race] smb驱动中存在潜在的data race
### Please make sure of the following things

- [X] I have read the [documentation](https://alist.nn.ci).
- [X] I'm sure there are no duplicate issues or discussions.
- [X] I'm sure it's due to `alist` and not something else(such as `Dependencies` or `Operational`).
- [x] I'm sure I'm using the latest version

### Alist Version / Alist 版本

latest

### Driver used / 使用的存储驱动

smb

### Describe the bug / 问题描述

smb驱动中多个方法调用和`updateLastConnTime()`来更新`d.lastConnTime`,同时也存在直接读取该变量的情况.  
并发的读写该变量可能会产生不可预料的问题,建议改成`int64`类型并用原子操作进行读写
```golang
func (d *SMB) updateLastConnTime() {
  d.lastConnTime = time.Now()
}
```
我愿意提交一个PR来修复此问题.

### Reproduction / 复现链接

N/A

### Logs / 日志

_No response_


Discussion / hints:
Thanks for opening your first issue here! Be sure to follow the issue template!


Fix patch:
diff --git a/drivers/smb/driver.go b/drivers/smb/driver.go
index 17875fe16f1..43f3e6834cf 100644
--- a/drivers/smb/driver.go
+++ b/drivers/smb/driver.go
@@ -5,7 +5,6 @@ import (
 	"errors"
 	"path/filepath"
 	"strings"
-	"time"
 
 	"github.com/alist-org/alist/v3/drivers/base"
 	"github.com/alist-org/alist/v3/internal/driver"
@@ -19,7 +18,7 @@ type SMB struct {
 	model.Storage
 	Addition
 	fs           *smb2.Share
-	lastConnTime time.Time
+	lastConnTime int64
 }
 
 func (d *SMB) Config() driver.Config {
diff --git a/drivers/smb/util.go b/drivers/smb/util.go
index 68d2ae32c93..f4605536da7 100644
--- a/drivers/smb/util.go
+++ b/drivers/smb/util.go
@@ -6,17 +6,22 @@ import (
 	"net"
 	"os"
 	"path/filepath"
+	"sync/atomic"
 	"time"
 
 	"github.com/hirochachacha/go-smb2"
 )
 
 func (d *SMB) updateLastConnTime() {
-	d.lastConnTime = time.Now()
+	atomic.StoreInt64(&d.lastConnTime, time.Now().Unix())
 }
 
 func (d *SMB) cleanLastConnTime() {
-	d.lastConnTime = time.Now().AddDate(0, 0, -1)
+	atomic.StoreInt64(&d.lastConnTime, 0)
+}
+
+func (d *SMB) getLastConnTime() time.Time {
+	return time.Unix(atomic.LoadInt64(&d.lastConnTime), 0)
 }
 
 func (d *SMB) initFS() error {
@@ -43,7 +48,7 @@ func (d *SMB) initFS() error {
 }
 
 func (d *SMB) checkConn() error {
-	if time.Since(d.lastConnTime) < 5*time.Minute {
+	if time.Since(d.getLastConnTime()) < 5*time.Minute {
 		return nil
 	}
 	if d.fs != nil {


Test patch: