Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- 手机截图写到专家自己的工作区。只改定时任务文案时,间隔任务不再重新计时
- 浏览器工作台恢复中文输入。主动关怀等对话安静后再发
- 向导密码随数据目录迁移。Linux 桌面无边框窗口可以拖边缘调整大小
- 桌面端(Windows)配置端口被占用时不会顺延到下一个空闲端口:端口探测误用 Windows 上恒不成立的 `syscall.EADDRINUSE`,现按平台匹配 `WSAEADDRINUSE`;同时修复 desktop Go 测试包因重复声明 `err` 而无法编译(Fixes #1905)

### 变更
- 云端协同默认打码对端地址和账号。共享来的资源在头像上做标记
Expand Down
1 change: 0 additions & 1 deletion desktop/src/filedrop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func TestDropServerServesOnlyPublishedFiles(t *testing.T) {
t.Fatal(err)
}
var resp *http.Response
var err error
for attempt := 0; attempt < 20; attempt++ {
resp, err = http.Get(base + "/0")
if err == nil {
Expand Down
4 changes: 1 addition & 3 deletions desktop/src/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"io"
"net"
Expand All @@ -13,7 +12,6 @@ import (
"runtime"
"strconv"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -219,7 +217,7 @@ func listenProbe(host string, port int) (bool, error) {
_ = ln.Close()
return false, nil
}
if errors.Is(err, syscall.EADDRINUSE) {
if addrInUse(err) {
return true, nil
}
return false, err
Expand Down
19 changes: 19 additions & 0 deletions desktop/src/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ func TestChooseFreePortStopsWhenHostCannotBind(t *testing.T) {
}
}

func TestChooseFreePortSkipsALiveListener(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
busy := ln.Addr().(*net.TCPAddr).Port
if busy > 65535-freePortScanLimit {
t.Skipf("ephemeral port %d leaves no room for a scan window", busy)
}
got, err := chooseFreePort("127.0.0.1", busy)
if err != nil {
t.Fatalf("chooseFreePort(%d) = %v", busy, err)
}
if got == busy {
t.Fatalf("chooseFreePort returned the busy port %d", busy)
}
}

func TestListenProbeSeesOpenListener(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions desktop/src/process_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"errors"
"os/exec"
"syscall"
)
Expand All @@ -15,3 +16,7 @@ func killProcessTree(cmd *exec.Cmd) {
_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGTERM)
_ = cmd.Wait()
}

func addrInUse(err error) bool {
return errors.Is(err, syscall.EADDRINUSE)
}
5 changes: 5 additions & 0 deletions desktop/src/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"errors"
"io"
"os/exec"
"strconv"
Expand All @@ -29,3 +30,7 @@ func killProcessTree(cmd *exec.Cmd) {
hideConsole(kill)
_ = kill.Run()
}

func addrInUse(err error) bool {
return errors.Is(err, windows.WSAEADDRINUSE)
}