4 Commits
Author SHA1 Message Date
kevin 6fd29fa5b2 fix: 全隧道模式跳过无意义的CIDR URL下载
Release / build-macos (push) Canceled after 0s
Release / build-windows (push) Canceled after 0s
Release / release (push) Canceled after 0s
全隧道模式下before-proxy、after-proxy和手动刷新三处仍会从URL
下载CIDR表,但下载结果永远不会被使用。添加ModeFull短路返回,
消除无意义的网络请求和连接延迟。

bump version to 0.6.9
2026-07-10 15:01:36 +08:00
kevin dc3e9beb14 chore: bump version to 0.6.8
Release / build-macos (push) Canceled after 0s
Release / build-windows (push) Canceled after 0s
Release / release (push) Canceled after 0s
2026-07-09 23:22:22 +08:00
kevin 9d7d4c8287 fix: 设为纯托盘应用,启动不再在Dock显示图标
将Info.plist的LSUIElement改为true,应用以accessory模式启动,
永不显示Dock图标和系统菜单栏。移除运行时切换Dock可见性的
showDockIcon()/hideDockIcon()及其C实现setDockIconVisible,
这些调用在accessory模式下已无意义。activateApp()保留用于
窗口置于前台获取焦点。
2026-07-09 23:20:10 +08:00
kevin 469106d502 fix: 修复raceDial竞态条件导致daemon死锁无法连接
raceDial在首个连接成功后cancel剩余拨号goroutine时,dial goroutine
的select有两个同时就绪的case(缓冲channel可发送 vs raceCtx.Done()),
Go随机选择可能导致结果未发送,使drain循环永久阻塞,进而导致daemon
持有d.mu死锁,所有IPC命令(stats/stop/新start)全部阻塞。

DNS解析返回IPv4+IPv6双地址时触发此bug,约50%概率死锁。

修复:移除select,直接发送到缓冲channel(容量=len(ips)永不阻塞),
多余连接由drain循环负责关闭。
2026-07-09 23:19:46 +08:00
9 changed files with 152 additions and 27 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ GO = go
CGO_ENABLED = 1 CGO_ENABLED = 1
WINDRES ?= x86_64-w64-mingw32-windres WINDRES ?= x86_64-w64-mingw32-windres
MINGW_CC ?= x86_64-w64-mingw32-gcc MINGW_CC ?= x86_64-w64-mingw32-gcc
SEMVER ?= 0.6.7 SEMVER ?= 0.6.9
GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) GIT_HASH = $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
VERSION = $(SEMVER)-$(GIT_HASH) VERSION = $(SEMVER)-$(GIT_HASH)
LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION) LDFLAGS = -s -w -X lmvpn/internal/version.Version=$(VERSION)
+9 -8
View File
@@ -99,13 +99,13 @@ func raceDial(ctx context.Context, network string, ips []string, port string) (n
go func(target string) { go func(target string) {
d := &net.Dialer{} d := &net.Dialer{}
c, err := d.DialContext(raceCtx, network, net.JoinHostPort(target, port)) c, err := d.DialContext(raceCtx, network, net.JoinHostPort(target, port))
select { // Always send the result: resultCh is buffered (len(ips)),
case resultCh <- result{conn: c, err: err}: // so this never blocks. Do NOT use a select with
case <-raceCtx.Done(): // <-raceCtx.Done() here - when the context is cancelled
if c != nil { // both cases would be ready and Go's random select pick
c.Close() // could skip the send, causing the drain loop below to
} // block forever.
} resultCh <- result{conn: c, err: err}
}(ip) }(ip)
} }
@@ -117,7 +117,8 @@ func raceDial(ctx context.Context, network string, ips []string, port string) (n
// any late successful connections. // any late successful connections.
cancel() cancel()
for j := i + 1; j < len(ips); j++ { for j := i + 1; j < len(ips); j++ {
if late := <-resultCh; late.conn != nil { late := <-resultCh
if late.conn != nil {
late.conn.Close() late.conn.Close()
} }
} }
+133
View File
@@ -0,0 +1,133 @@
package transport
import (
"context"
"net"
"sync"
"testing"
"time"
)
// TestRaceDialNoDeadlock is a regression test for a select race
// condition that caused raceDial to deadlock ~50% of the time when
// multiple IPs were raced and the first succeeded. The bug was a
// select with two simultaneously-ready cases (send result vs
// <-raceCtx.Done()); Go's random selection could skip the send,
// leaving the drain loop blocked forever.
//
// We run many iterations because the bug was probabilistic.
func TestRaceDialNoDeadlock(t *testing.T) {
const iterations = 200
for n := 0; n < iterations; n++ {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
// Accept both connections in background (both IPs dial the
// same listener since raceDial uses a single port).
go func() {
for {
c, err := ln.Accept()
if err != nil {
return
}
c.Close()
}
}()
port := portOf(ln.Addr())
ips := []string{"127.0.0.1", "127.0.0.1"}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
conn, err := raceDial(ctx, "tcp", ips, port)
cancel()
if err == nil && conn != nil {
conn.Close()
}
ln.Close()
// If we get here without the 5s timeout, the iteration passed.
// A deadlock would trigger the test-wide 60s timeout.
}
// If we reach here, no iteration deadlocked.
}
// TestRaceDialAllFail verifies that when all dials fail, raceDial
// returns an error instead of blocking.
func TestRaceDialAllFail(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// Port 1: connection refused on most systems.
ips := []string{"127.0.0.1", "127.0.0.1"}
_, err := raceDial(ctx, "tcp", ips, "1")
if err == nil {
t.Fatal("expected error when all dials fail")
}
}
// TestRaceDialSingleIP verifies the single-IP path still works.
func TestRaceDialSingleIP(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
c, _ := ln.Accept()
if c != nil {
c.Close()
}
}()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
conn, err := raceDial(ctx, "tcp", []string{"127.0.0.1"}, portOf(ln.Addr()))
if err != nil {
t.Fatalf("raceDial single IP: %v", err)
}
conn.Close()
wg.Wait()
}
// TestRaceDialContextCancelled ensures raceDial returns promptly when
// the parent context is cancelled while dials are in flight.
func TestRaceDialContextCancelled(t *testing.T) {
// Dial a non-routable address so the dial hangs until context
// cancellation.
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.Sleep(200 * time.Millisecond)
cancel()
}()
done := make(chan error, 1)
go func() {
_, err := raceDial(ctx, "tcp", []string{"10.255.255.1", "10.255.255.2"}, "80")
done <- err
}()
select {
case err := <-done:
if err == nil {
t.Fatal("expected error on cancelled context")
}
case <-time.After(5 * time.Second):
t.Fatal("raceDial did not return after context cancellation")
}
}
// portOf extracts the port from a net.Addr.
func portOf(addr net.Addr) string {
_, port, _ := net.SplitHostPort(addr.String())
return port
}
-3
View File
@@ -130,7 +130,6 @@ func Run() {
fyne.Do(func() { fyne.Do(func() {
a.windowHidden = false a.windowHidden = false
activateApp() activateApp()
showDockIcon()
a.window.Show() a.window.Show()
a.window.RequestFocus() a.window.RequestFocus()
}) })
@@ -149,7 +148,6 @@ func Run() {
if a.windowHidden { if a.windowHidden {
a.windowHidden = false a.windowHidden = false
activateApp() activateApp()
showDockIcon()
fyne.Do(func() { fyne.Do(func() {
if a.windowHidden { if a.windowHidden {
return return
@@ -173,7 +171,6 @@ func Run() {
a.window.SetCloseIntercept(func() { a.window.SetCloseIntercept(func() {
if cfg.CloseToTray { if cfg.CloseToTray {
a.windowHidden = true a.windowHidden = true
hideDockIcon()
a.window.Hide() a.window.Hide()
} else { } else {
a.quit() a.quit()
-9
View File
@@ -25,12 +25,6 @@ static BOOL appShouldHandleReopen(id self, SEL cmd, id sender, BOOL flag) {
return YES; return YES;
} }
static void setDockIconVisible(int visible) {
Class cls = objc_getClass("NSApplication");
id app = ((id (*)(Class, SEL))objc_msgSend)(cls, sel_getUid("sharedApplication"));
((void (*)(id, SEL, long))objc_msgSend)(app, sel_getUid("setActivationPolicy:"), visible ? 0 : 1);
}
static void cmActivateApp(void) { static void cmActivateApp(void) {
Class cls = objc_getClass("NSApplication"); Class cls = objc_getClass("NSApplication");
id app = ((id (*)(Class, SEL))objc_msgSend)(cls, sel_getUid("sharedApplication")); id app = ((id (*)(Class, SEL))objc_msgSend)(cls, sel_getUid("sharedApplication"));
@@ -53,9 +47,6 @@ static void cmRegisterReopenHandler(void) {
*/ */
import "C" import "C"
func showDockIcon() { C.setDockIconVisible(1) }
func hideDockIcon() { C.setDockIconVisible(0) }
func activateApp() { C.cmActivateApp() } func activateApp() { C.cmActivateApp() }
func registerReopenHandler() { C.cmRegisterReopenHandler() } func registerReopenHandler() { C.cmRegisterReopenHandler() }
-3
View File
@@ -4,9 +4,6 @@ package ui
var onAppActive func() var onAppActive func()
func showDockIcon() {}
func hideDockIcon() {}
func activateApp() {} func activateApp() {}
func registerReopenHandler() {} func registerReopenHandler() {}
-1
View File
@@ -63,7 +63,6 @@ func (a *App) setupTray() {
fyne.NewMenuItem(i18n.T("TrayShowWindow"), func() { fyne.NewMenuItem(i18n.T("TrayShowWindow"), func() {
a.windowHidden = false a.windowHidden = false
activateApp() activateApp()
showDockIcon()
a.window.Show() a.window.Show()
a.window.RequestFocus() a.window.RequestFocus()
}), }),
+8 -1
View File
@@ -197,7 +197,7 @@ func (sm *SessionManager) run(ctx context.Context, cfg SessionConfig) {
// to avoid consuming the server's 30s ReadyTimeout budget. // to avoid consuming the server's 30s ReadyTimeout budget.
var beforeCIDRs []string var beforeCIDRs []string
allURLSources := append(append([]model.CIDRURLSource{}, cfg.CIDRV4URLs...), cfg.CIDRV6URLs...) allURLSources := append(append([]model.CIDRURLSource{}, cfg.CIDRV4URLs...), cfg.CIDRV6URLs...)
if len(allURLSources) > 0 { if len(allURLSources) > 0 && cfg.RoutingMode != route.ModeFull {
sm.stats.SetConnectStep("fetch_cidrs") sm.stats.SetConnectStep("fetch_cidrs")
sm.setState(stats.StateConnecting) sm.setState(stats.StateConnecting)
log.L().Info("fetching before-proxy CIDR lists", "url_count", len(allURLSources)) log.L().Info("fetching before-proxy CIDR lists", "url_count", len(allURLSources))
@@ -588,6 +588,9 @@ func (sm *SessionManager) setupTUN(init protocol.InitMessage, cfg SessionConfig,
// (via the tunnel) and dynamically adds their routes to the route // (via the tunnel) and dynamically adds their routes to the route
// manager. This is called in a goroutine after the data plane is up. // manager. This is called in a goroutine after the data plane is up.
func (sm *SessionManager) fetchAfterProxyCIDRs(ctx context.Context, cfg SessionConfig) { func (sm *SessionManager) fetchAfterProxyCIDRs(ctx context.Context, cfg SessionConfig) {
if cfg.RoutingMode == route.ModeFull {
return
}
allURLSources := append(append([]model.CIDRURLSource{}, cfg.CIDRV4URLs...), cfg.CIDRV6URLs...) allURLSources := append(append([]model.CIDRURLSource{}, cfg.CIDRV4URLs...), cfg.CIDRV6URLs...)
// Count only "after" sources for logging. // Count only "after" sources for logging.
afterCount := 0 afterCount := 0
@@ -659,6 +662,10 @@ func (sm *SessionManager) RefreshCIDRs() {
return return
} }
if cfg.RoutingMode == route.ModeFull {
return
}
// Use a background context with 30s timeout so the refresh works // Use a background context with 30s timeout so the refresh works
// even if the session context is in a weird state. // even if the session context is in a weird state.
refreshCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) refreshCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+1 -1
View File
@@ -32,7 +32,7 @@
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>
<true/> <true/>
<key>LSUIElement</key> <key>LSUIElement</key>
<false/> <true/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>
<dict> <dict>
<key>NSAllowsArbitraryLoads</key> <key>NSAllowsArbitraryLoads</key>