Fix stale proxy state after connection loss (#251)

This commit is contained in:
Gerhard Tan
2025-06-18 17:26:34 +08:00
committed by GitHub
parent b2c716163c
commit ef4362bd76
3 changed files with 41 additions and 38 deletions

View File

@ -125,16 +125,7 @@ type ProxyModel struct {
rowRenamedPublisher walk.IntEventPublisher
}
type ProxyRow struct {
*config.Proxy
// Domains is a list of domains bound to this proxy
Domains string
// DisplayLocalIP changes the local address shown in table
DisplayLocalIP string
// DisplayLocalPort changes the local port shown in table
DisplayLocalPort string
// DisplayRemotePort changes the remote port shown in table.
DisplayRemotePort string
type ProxyStatusInfo struct {
// Running state.
State consts.ProxyState
// Error message.
@ -145,6 +136,19 @@ type ProxyRow struct {
RemoteAddr string
}
type ProxyRow struct {
*config.Proxy
ProxyStatusInfo
// Domains is a list of domains bound to this proxy
Domains string
// DisplayLocalIP changes the local address shown in table
DisplayLocalIP string
// DisplayLocalPort changes the local port shown in table
DisplayLocalPort string
// DisplayRemotePort changes the remote port shown in table.
DisplayRemotePort string
}
func NewProxyRow(p *config.Proxy) *ProxyRow {
return fillProxyRow(p, new(ProxyRow))
}

View File

@ -112,33 +112,35 @@ func (pt *ProxyTracker) onMessage(msg []ipc.ProxyMessage) {
stat[pxy] = pm
}
}
if len(stat) > 0 {
pt.owner.Synchronize(func() {
if pt.ctx.Err() != nil {
return
pt.owner.Synchronize(func() {
if pt.ctx.Err() != nil {
return
}
for i, item := range pt.model.items {
if item.Disabled {
continue
}
for i, item := range pt.model.items {
if item.Disabled {
continue
}
if m, ok := stat[item.Proxy]; ok {
state, _ := proxyPhaseToProxyState(m.Status)
if item.State != state || item.Error != m.Err || item.RemoteAddr != m.RemoteAddr || item.StateSource != m.Name {
item.State = state
item.Error = m.Err
item.StateSource = m.Name
item.RemoteAddr = m.RemoteAddr
item.UpdateRemotePort()
pt.model.PublishRowChanged(i)
if pt.refreshTimer != nil {
pt.refreshTimer.Stop()
pt.refreshTimer = nil
}
}
var statusInfo ProxyStatusInfo
if m, ok := stat[item.Proxy]; ok {
state, _ := proxyPhaseToProxyState(m.Status)
statusInfo = ProxyStatusInfo{
State: state,
Error: m.Err,
StateSource: m.Name,
RemoteAddr: m.RemoteAddr,
}
}
})
}
if item.ProxyStatusInfo != statusInfo {
item.ProxyStatusInfo = statusInfo
item.UpdateRemotePort()
pt.model.PublishRowChanged(i)
if pt.refreshTimer != nil {
pt.refreshTimer.Stop()
pt.refreshTimer = nil
}
}
}
})
}
func (pt *ProxyTracker) buildCache() {

View File

@ -127,10 +127,7 @@ func (pv *ProxyView) resetProxyState(row int) {
defer pv.table.DisposeImageList()
}
for i, item := range items {
item.State = consts.ProxyStateUnknown
item.StateSource = ""
item.Error = ""
item.RemoteAddr = ""
item.ProxyStatusInfo = ProxyStatusInfo{}
if item.RemotePort != item.DisplayRemotePort {
item.DisplayRemotePort = item.RemotePort
if row < 0 {