Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ce5016

Browse files
committedJan 29, 2025
Remove grpcsync.OnceFunc as OnceFunc is part of standard sync lib starting go1.22
1 parent 73e4470 commit 9ce5016

File tree

11 files changed

+15
-102
lines changed

11 files changed

+15
-102
lines changed
 

‎balancer_wrapper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (acbw *acBalancerWrapper) GetOrBuildProducer(pb balancer.ProducerBuilder) (
415415
}
416416
acbw.producersMu.Unlock()
417417
}
418-
return pData.producer, grpcsync.OnceFunc(unref)
418+
return pData.producer, sync.OnceFunc(unref)
419419
}
420420

421421
func (acbw *acBalancerWrapper) closeProducers() {

‎internal/grpcsync/oncefunc.go

-32
This file was deleted.

‎internal/grpcsync/oncefunc_test.go

-53
This file was deleted.

‎internal/xds/bootstrap/tlscreds/bundle.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import (
2727
"errors"
2828
"fmt"
2929
"net"
30+
"sync"
3031

3132
"google.golang.org/grpc/credentials"
3233
"google.golang.org/grpc/credentials/tls/certprovider"
3334
"google.golang.org/grpc/credentials/tls/certprovider/pemfile"
34-
"google.golang.org/grpc/internal/grpcsync"
3535
)
3636

3737
// bundle is an implementation of credentials.Bundle which implements mTLS
@@ -81,7 +81,7 @@ func NewBundle(jd json.RawMessage) (credentials.Bundle, func(), error) {
8181
}
8282
return &bundle{
8383
transportCredentials: &reloadingCreds{provider: provider},
84-
}, grpcsync.OnceFunc(func() { provider.Close() }), nil
84+
}, sync.OnceFunc(func() { provider.Close() }), nil
8585
}
8686

8787
func (t *bundle) TransportCredentials() credentials.TransportCredentials {

‎orca/producer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"google.golang.org/grpc/balancer"
2626
"google.golang.org/grpc/codes"
2727
"google.golang.org/grpc/internal/backoff"
28-
"google.golang.org/grpc/internal/grpcsync"
2928
"google.golang.org/grpc/orca/internal"
3029
"google.golang.org/grpc/status"
3130

@@ -85,7 +84,7 @@ func RegisterOOBListener(sc balancer.SubConn, l OOBListener, opts OOBListenerOpt
8584

8685
// If stop is called multiple times, prevent it from having any effect on
8786
// subsequent calls.
88-
return grpcsync.OnceFunc(func() {
87+
return sync.OnceFunc(func() {
8988
p.unregisterListener(l, opts.ReportInterval)
9089
closeFn()
9190
})

‎server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func (s *Server) serverWorker() {
643643
// connections to reduce the time spent overall on runtime.morestack.
644644
func (s *Server) initServerWorkers() {
645645
s.serverWorkerChannel = make(chan func())
646-
s.serverWorkerChannelClose = grpcsync.OnceFunc(func() {
646+
s.serverWorkerChannelClose = sync.OnceFunc(func() {
647647
close(s.serverWorkerChannel)
648648
})
649649
for i := uint32(0); i < s.opts.numServerWorkers; i++ {
@@ -1930,7 +1930,7 @@ func (s *Server) stop(graceful bool) {
19301930
s.conns = nil
19311931

19321932
if s.opts.numServerWorkers > 0 {
1933-
// Closing the channel (only once, via grpcsync.OnceFunc) after all the
1933+
// Closing the channel (only once, via sync.OnceFunc) after all the
19341934
// connections have been closed above ensures that there are no
19351935
// goroutines executing the callback passed to st.HandleStreams (where
19361936
// the channel is written to).

‎xds/internal/resolver/xds_resolver_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"encoding/json"
2424
"fmt"
2525
"strings"
26+
"sync"
2627
"testing"
2728
"time"
2829

@@ -32,7 +33,6 @@ import (
3233
"github.com/google/uuid"
3334
"google.golang.org/grpc/codes"
3435
"google.golang.org/grpc/internal"
35-
"google.golang.org/grpc/internal/grpcsync"
3636
iresolver "google.golang.org/grpc/internal/resolver"
3737
"google.golang.org/grpc/internal/testutils"
3838
"google.golang.org/grpc/internal/testutils/xds/e2e"
@@ -271,7 +271,7 @@ func (s) TestResolverCloseClosesXDSClient(t *testing.T) {
271271
Name: t.Name(),
272272
WatchExpiryTimeout: defaultTestTimeout,
273273
})
274-
return c, grpcsync.OnceFunc(func() {
274+
return c, sync.OnceFunc(func() {
275275
close(closeCh)
276276
cancel()
277277
}), err

‎xds/internal/xdsclient/authority.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package xdsclient
2020
import (
2121
"context"
2222
"fmt"
23+
"sync"
2324
"sync/atomic"
2425

2526
"google.golang.org/grpc/grpclog"
@@ -674,7 +675,7 @@ func (a *authority) watchResource(rType xdsresource.Type, resourceName string, w
674675
}
675676

676677
func (a *authority) unwatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) func() {
677-
return grpcsync.OnceFunc(func() {
678+
return sync.OnceFunc(func() {
678679
done := make(chan struct{})
679680
a.xdsClientSerializer.ScheduleOr(func(context.Context) {
680681
defer close(done)

‎xds/internal/xdsclient/clientimpl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (c *clientImpl) getOrCreateChannel(serverConfig *bootstrap.ServerConfig, in
342342
// reference to the xdsChannel. This returned function is idempotent, meaning
343343
// it can be called multiple times without any additional effect.
344344
func (c *clientImpl) releaseChannel(serverConfig *bootstrap.ServerConfig, state *channelState, deInitLocked func(*channelState)) func() {
345-
return grpcsync.OnceFunc(func() {
345+
return sync.OnceFunc(func() {
346346
c.channelsMu.Lock()
347347

348348
if c.logger.V(2) {

‎xds/internal/xdsclient/pool.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
v3statuspb "github.com/envoyproxy/go-control-plane/envoy/service/status/v3"
2727
"google.golang.org/grpc/internal/backoff"
28-
"google.golang.org/grpc/internal/grpcsync"
2928
"google.golang.org/grpc/internal/xds/bootstrap"
3029
)
3130

@@ -131,7 +130,7 @@ func (p *Pool) GetClientForTesting(name string) (XDSClient, func(), error) {
131130
return nil, nil, fmt.Errorf("xds:: xDS client with name %q not found", name)
132131
}
133132
c.incrRef()
134-
return c, grpcsync.OnceFunc(func() { p.clientRefCountedClose(name) }), nil
133+
return c, sync.OnceFunc(func() { p.clientRefCountedClose(name) }), nil
135134
}
136135

137136
// SetFallbackBootstrapConfig is used to specify a bootstrap configuration
@@ -193,7 +192,7 @@ func (p *Pool) newRefCounted(name string, watchExpiryTimeout time.Duration, stre
193192

194193
if c := p.clients[name]; c != nil {
195194
c.incrRef()
196-
return c, grpcsync.OnceFunc(func() { p.clientRefCountedClose(name) }), nil
195+
return c, sync.OnceFunc(func() { p.clientRefCountedClose(name) }), nil
197196
}
198197

199198
c, err := newClientImpl(p.config, watchExpiryTimeout, streamBackoff)
@@ -208,5 +207,5 @@ func (p *Pool) newRefCounted(name string, watchExpiryTimeout time.Duration, stre
208207
xdsClientImplCreateHook(name)
209208

210209
logger.Infof("xDS node ID: %s", p.config.Node().GetId())
211-
return client, grpcsync.OnceFunc(func() { p.clientRefCountedClose(name) }), nil
210+
return client, sync.OnceFunc(func() { p.clientRefCountedClose(name) }), nil
212211
}

‎xds/internal/xdsclient/transport/lrs/lrs_stream.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"google.golang.org/grpc/grpclog"
3030
"google.golang.org/grpc/internal/backoff"
3131
igrpclog "google.golang.org/grpc/internal/grpclog"
32-
"google.golang.org/grpc/internal/grpcsync"
3332
"google.golang.org/grpc/internal/pretty"
3433
"google.golang.org/grpc/xds/internal"
3534
"google.golang.org/grpc/xds/internal/xdsclient/load"
@@ -107,7 +106,7 @@ func (lrs *StreamImpl) ReportLoad() (*load.Store, func()) {
107106
lrs.mu.Lock()
108107
defer lrs.mu.Unlock()
109108

110-
cleanup := grpcsync.OnceFunc(func() {
109+
cleanup := sync.OnceFunc(func() {
111110
lrs.mu.Lock()
112111
defer lrs.mu.Unlock()
113112

0 commit comments

Comments
 (0)