mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: don't activate alarm w/missing AlarmType
Narrowly prevent etcd from crashing when given a bad ACTIVATE payload, e.g.: $ curl -d "{\"action\":\"ACTIVATE\"}" ${ETCD}/v3/maintenance/alarm curl: (52) Empty reply from server
This commit is contained in:
parent
ab20aa29a0
commit
ae194c1470
@ -721,6 +721,9 @@ func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
|
||||
case pb.AlarmRequest_GET:
|
||||
resp.Alarms = a.s.alarmStore.Get(ar.Alarm)
|
||||
case pb.AlarmRequest_ACTIVATE:
|
||||
if ar.Alarm == pb.AlarmType_NONE {
|
||||
break
|
||||
}
|
||||
m := a.s.alarmStore.Activate(types.ID(ar.MemberID), ar.Alarm)
|
||||
if m == nil {
|
||||
break
|
||||
@ -738,7 +741,7 @@ func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
|
||||
case pb.AlarmType_NOSPACE:
|
||||
a.s.applyV3 = newApplierV3Capped(a)
|
||||
default:
|
||||
lg.Warn("unimplemented alarm activation", zap.String("alarm", fmt.Sprintf("%+v", m)))
|
||||
lg.Panic("unimplemented alarm activation", zap.String("alarm", fmt.Sprintf("%+v", m)))
|
||||
}
|
||||
case pb.AlarmRequest_DEACTIVATE:
|
||||
m := a.s.alarmStore.Deactivate(types.ID(ar.MemberID), ar.Alarm)
|
||||
|
@ -366,6 +366,21 @@ func testV3CurlResignMissiongLeaderKey(cx ctlCtx) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestV3CurlMaintenanceAlarmMissiongAlarm(t *testing.T) {
|
||||
for _, p := range apiPrefix {
|
||||
testCtl(t, testV3CurlMaintenanceAlarmMissiongAlarm, withApiPrefix(p), withCfg(*newConfigNoTLS()))
|
||||
}
|
||||
}
|
||||
|
||||
func testV3CurlMaintenanceAlarmMissiongAlarm(cx ctlCtx) {
|
||||
if err := cURLPost(cx.epc, cURLReq{
|
||||
endpoint: path.Join(cx.apiPrefix, "/maintenance/alarm"),
|
||||
value: `{"action": "ACTIVATE"}`,
|
||||
}); err != nil {
|
||||
cx.t.Fatalf("failed post maintenance alarm (%s) (%v)", cx.apiPrefix, err)
|
||||
}
|
||||
}
|
||||
|
||||
// to manually decode; JSON marshals integer fields with
|
||||
// string types, so can't unmarshal with epb.CampaignResponse
|
||||
type campaignResponse struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user