From 8293b27c193087a8f31a6f6f3a9dd06d815b5d1d Mon Sep 17 00:00:00 2001 From: QiuSW <105186638@qq.com> Date: Sat, 12 Sep 2026 09:34:44 +0800 Subject: [PATCH] fix(syb): retry drifting sync page once (#270) --- server/app/goauto/sybimport/sync.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/app/goauto/sybimport/sync.go b/server/app/goauto/sybimport/sync.go index 757dff0..3cd5a7d 100644 --- a/server/app/goauto/sybimport/sync.go +++ b/server/app/goauto/sybimport/sync.go @@ -285,6 +285,24 @@ func loadDailyList(ctx context.Context, client *sybclient.Client, date string, p if pageCount != len(page) { return nil, fmt.Errorf("%s 货运单列表第 %d 页响应条数不自洽:total=%d,list=%d", date, pageIndex, pageCount, len(page)) } + // SYB may change a page while the list is being read. Re-read once + // before treating a boundary-page count drift as a fatal snapshot error. + if len(page) != expectedPageCount { + pause := time.NewTimer(500 * time.Millisecond) + select { + case <-ctx.Done(): + pause.Stop() + return nil, ctx.Err() + case <-pause.C: + } + page, pageCount, err = client.ListPage(ctx, date, date, start, pageIndex, pageSize) + if err != nil { + return nil, fmt.Errorf("重读 %s 货运单列表第 %d 页失败:%w", date, pageIndex, err) + } + if pageCount != len(page) { + return nil, fmt.Errorf("%s 货运单列表第 %d 页重读响应条数不自洽:total=%d,list=%d", date, pageIndex, pageCount, len(page)) + } + } // Validate the whole page first: a same-page duplicate must not be // hidden behind an earlier, recoverable cross-page overlap. pageSeen := make(map[int64]int, len(page))