Skip to content

Commit c29ca13

Browse files
committed
core/async: return nil values w/ Grx even on errs
1 parent 4b244d6 commit c29ca13

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

intra/core/async.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ func Grx[T any](who string, f WorkCtx[T], d time.Duration) (zz T, completed bool
7878
defer Recover(Exit11, who)
7979
defer close(ch)
8080

81-
if out, err := f(ctx); err == nil {
82-
ch <- out
83-
} // else: discard
81+
out, _ := f(ctx) // TODO: log error?
82+
ch <- out
8483
}()
8584

8685
select {

intra/core/barrier.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (ba *Barrier[T, K]) Do(k K, once Work[T]) (*V[T, K], int) {
195195
c.Val, c.Err = once()
196196
return c, c.Err
197197
}, ba.to); !completed {
198-
c.Err = errTimeout
198+
c.Err = JoinErr(c.Err, errTimeout)
199199
}
200200

201201
c.wg.Done() // unblock all waiters
@@ -220,7 +220,7 @@ func (ba *Barrier[T, K]) Do1(k K, once Work1[T], arg T) (*V[T, K], int) {
220220
c.Val, c.Err = once(arg)
221221
return c, c.Err
222222
}, ba.to); !completed {
223-
c.Err = errTimeout
223+
c.Err = JoinErr(c.Err, errTimeout)
224224
}
225225

226226
c.wg.Done() // unblock all waiters

intra/dnsx/alg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,15 +676,15 @@ func (t *dnsgateway) qs(t2 Transport, uid, network string, msg *dns.Msg, t1res <
676676

677677
qname := xdns.QName(msg)
678678

679-
r, ok := core.Grx("alg.qs."+qname, func(_ context.Context) (secans, error) {
679+
r, completed := core.Grx("alg.qs."+qname, func(_ context.Context) (secans, error) {
680680
return t.querySecondary(t2, uid, network, msg, t1res), nil
681681
}, timeout)
682682

683-
if !ok {
683+
if !completed {
684684
log.W("alg: skip; qs timeout; tr2: %s, qname: %s", idstr(t2), qname)
685685
}
686686

687-
r.initIfNeeded() // r may be nil on Grx:timeout
687+
r.initIfNeeded() // r may be nil value on Grx:timeout
688688

689689
t2res <- r // may be zero secans
690690
}()

intra/dnsx/transport.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,11 @@ func (r *resolver) forward(q []byte, uid string, chosenids ...string) (res0 []by
510510
return nil, NoDNS, errMissingQueryName
511511
}
512512

513-
pref, oqok := core.Grx("r.onQuery", func(_ context.Context) (*x.DNSOpts, error) {
513+
pref, oqcompleted := core.Grx("r.onQuery", func(_ context.Context) (*x.DNSOpts, error) {
514514
return r.listener.OnQuery(uid, qname, qtyp), nil
515515
}, onQueryTimeout)
516-
if !oqok {
517-
log.W("dns: fwd: for %s; no preferences for %s:%d", uid, qname, qtyp)
516+
if !oqcompleted || pref == nil {
517+
log.W("dns: fwd: for %s; no preferences (%t) for %s:%d", uid, pref == nil, qname, qtyp)
518518
smm.Latency = time.Since(starttime).Seconds()
519519
smm.Status = ClientError
520520
smm.Msg = errOnQueryTimeout.Error()

intra/ipn/proxies.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,14 @@ func (px *proxifier) ProxyFor(id string) (Proxy, error) {
629629
}
630630

631631
// go.dev/play/p/xCug1W3OcMH
632-
p, ok := core.Grx("pxr.ProxyFor: "+id, func(_ context.Context) (Proxy, error) {
632+
p, completed := core.Grx("pxr.ProxyFor: "+id, func(_ context.Context) (Proxy, error) {
633633
px.RLock()
634634
defer px.RUnlock()
635635

636636
return px.p[id], nil
637637
}, getproxytimeout)
638638

639-
if !ok {
639+
if !completed {
640640
log.W("proxy: for: %s; timeout!", id)
641641
// possibly a deadlock, so return an error
642642
return nil, errGetProxyTimeout

0 commit comments

Comments
 (0)