Skip to content

Commit 1ab3cde

Browse files
authored
Merge pull request #8945 from sbueringer/pr-improve-locking
🌱 test/e2e/in-memory: improve locking, return errors instead of panic
2 parents 8ccb67c + d83b50e commit 1ab3cde

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

test/infrastructure/inmemory/internal/server/api/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func requestToGVK(req *restful.Request) (*schema.GroupVersionKind, error) {
542542
}
543543
gv, err := schema.ParseGroupVersion(resourceList.GroupVersion)
544544
if err != nil {
545-
panic(fmt.Sprintf("invalid group version in APIResourceList: %s", resourceList.GroupVersion))
545+
return nil, errors.Errorf("invalid group version in APIResourceList: %s", resourceList.GroupVersion)
546546
}
547547

548548
resource := req.PathParameter("resource")

test/infrastructure/inmemory/internal/server/api/watch.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func (h *apiServerHandler) watchForResource(req *restful.Request, resp *restful.
9797
h.log.Info(fmt.Sprintf("Serving Watch for %v", req.Request.URL))
9898
// With an unbuffered event channel RemoveEventHandler could be blocked because it requires a lock on the informer.
9999
// When Run stops reading from the channel the informer could be blocked with an unbuffered chanel and then RemoveEventHandler never goes through.
100-
events := make(chan *Event, 10)
100+
// 1000 is used to avoid deadlocks in clusters with a higher number of Machines/Nodes.
101+
events := make(chan *Event, 1000)
101102
watcher := &WatchEventDispatcher{
102103
resourceGroup: resourceGroup,
103104
events: events,
@@ -109,8 +110,8 @@ func (h *apiServerHandler) watchForResource(req *restful.Request, resp *restful.
109110

110111
// Defer cleanup which removes the event handler and ensures the channel is empty of events.
111112
defer func() {
112-
reterr = i.RemoveEventHandler(watcher)
113113
// Doing this to ensure the channel is empty.
114+
// This reduces the probability of a deadlock when removing the event handler.
114115
L:
115116
for {
116117
select {
@@ -119,6 +120,8 @@ func (h *apiServerHandler) watchForResource(req *restful.Request, resp *restful.
119120
break L
120121
}
121122
}
123+
reterr = i.RemoveEventHandler(watcher)
124+
// Note: After we removed the handler, no new events will be written to the events channel.
122125
}()
123126

124127
return watcher.Run(ctx, queryTimeout, resp)

test/infrastructure/inmemory/internal/server/etcd/handler.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,27 @@ func (m *maintenanceServer) Status(ctx context.Context, _ *pb.StatusRequest) (*p
9898
}
9999

100100
func (m *maintenanceServer) Defragment(_ context.Context, _ *pb.DefragmentRequest) (*pb.DefragmentResponse, error) {
101-
panic("implement me")
101+
return nil, fmt.Errorf("not implemented: Defragment")
102102
}
103103

104104
func (m *maintenanceServer) Hash(_ context.Context, _ *pb.HashRequest) (*pb.HashResponse, error) {
105-
panic("implement me")
105+
return nil, fmt.Errorf("not implemented: Hash")
106106
}
107107

108108
func (m *maintenanceServer) HashKV(_ context.Context, _ *pb.HashKVRequest) (*pb.HashKVResponse, error) {
109-
panic("implement me")
109+
return nil, fmt.Errorf("not implemented: HashKV")
110110
}
111111

112112
func (m *maintenanceServer) Snapshot(_ *pb.SnapshotRequest, _ pb.Maintenance_SnapshotServer) error {
113-
panic("implement me")
113+
return fmt.Errorf("not implemented: Snapshot")
114114
}
115115

116116
func (m *maintenanceServer) MoveLeader(_ context.Context, _ *pb.MoveLeaderRequest) (*pb.MoveLeaderResponse, error) {
117-
panic("implement me")
117+
return nil, fmt.Errorf("not implemented: MoveLeader")
118118
}
119119

120120
func (m *maintenanceServer) Downgrade(_ context.Context, _ *pb.DowngradeRequest) (*pb.DowngradeResponse, error) {
121-
panic("implement me")
121+
return nil, fmt.Errorf("not implemented: Downgrade")
122122
}
123123

124124
// clusterServerServer implements the ClusterServer grpc server.
@@ -127,15 +127,15 @@ type clusterServerServer struct {
127127
}
128128

129129
func (c *clusterServerServer) MemberAdd(_ context.Context, _ *pb.MemberAddRequest) (*pb.MemberAddResponse, error) {
130-
panic("implement me")
130+
return nil, fmt.Errorf("not implemented: MemberAdd")
131131
}
132132

133133
func (c *clusterServerServer) MemberRemove(_ context.Context, _ *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) {
134-
panic("implement me")
134+
return nil, fmt.Errorf("not implemented: MemberRemove")
135135
}
136136

137137
func (c *clusterServerServer) MemberUpdate(_ context.Context, _ *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) {
138-
panic("implement me")
138+
return nil, fmt.Errorf("not implemented: MemberUpdate")
139139
}
140140

141141
func (c *clusterServerServer) MemberList(ctx context.Context, _ *pb.MemberListRequest) (*pb.MemberListResponse, error) {
@@ -155,7 +155,7 @@ func (c *clusterServerServer) MemberList(ctx context.Context, _ *pb.MemberListRe
155155
}
156156

157157
func (c *clusterServerServer) MemberPromote(_ context.Context, _ *pb.MemberPromoteRequest) (*pb.MemberPromoteResponse, error) {
158-
panic("implement me")
158+
return nil, fmt.Errorf("not implemented: MemberPromote")
159159
}
160160

161161
type baseServer struct {

0 commit comments

Comments
 (0)