Commit 9fcd645d authored by Loïck Bonniot's avatar Loïck Bonniot

Merge branch 'fix-room-hanged-bis-23' into 'master'

[p] Try to fix hanged rooms

Closes #23

See merge request !93
parents 4f119d7b e8a9cc12
Pipeline #2358 passed with stages
...@@ -33,8 +33,9 @@ var ReadySignTimeout = time.Minute ...@@ -33,8 +33,9 @@ var ReadySignTimeout = time.Minute
func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *context.Context, in *api.ReadySignRequest) *api.LaunchSignature { func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *context.Context, in *api.ReadySignRequest) *api.LaunchSignature {
roomID := "ready_" + in.ContractUuid roomID := "ready_" + in.ContractUuid
channel, _, first := rooms.Join(roomID) channel, _, first := rooms.Join(roomID)
cn := net.GetCN(ctx) defer rooms.Unjoin(roomID, channel)
cn := net.GetCN(ctx)
// Check UUID // Check UUID
if !bson.IsObjectIdHex(in.ContractUuid) { if !bson.IsObjectIdHex(in.ContractUuid) {
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}} return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}}
...@@ -71,10 +72,8 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex ...@@ -71,10 +72,8 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}} return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}}
} }
case <-(*ctx).Done(): // Client's disconnection case <-(*ctx).Done(): // Client's disconnection
rooms.Unjoin(roomID, channel)
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}} return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_INVARG}}
case <-timeout: // Someone has not confirmed the signature within the delay case <-timeout: // Someone has not confirmed the signature within the delay
rooms.Unjoin(roomID, channel)
return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_TIMEOUT, Message: "timeout for ready signal"}} return &api.LaunchSignature{ErrorCode: &api.ErrorCode{Code: api.ErrorCode_TIMEOUT, Message: "timeout for ready signal"}}
} }
} }
...@@ -86,6 +85,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex ...@@ -86,6 +85,7 @@ func ReadySign(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, ctx *contex
func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, contractUUID string) { func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, contractUUID string) {
roomID := "ready_" + contractUUID roomID := "ready_" + contractUUID
channel, oldMessages, _ := rooms.Join(roomID) channel, oldMessages, _ := rooms.Join(roomID)
defer rooms.Unjoin(roomID, channel)
// Push oldMessages into the channel. // Push oldMessages into the channel.
// It is safe as this sould be a very small slice (the room is just created). // It is safe as this sould be a very small slice (the room is just created).
...@@ -102,7 +102,6 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co ...@@ -102,7 +102,6 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co
ready: true, ready: true,
data: "", data: "",
}) // This represents a "error" response }) // This represents a "error" response
rooms.Unjoin(roomID, channel)
return return
} }
...@@ -132,7 +131,6 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co ...@@ -132,7 +131,6 @@ func masterReadyRoutine(db *mgdb.MongoManager, rooms *common.WaitingGroupMap, co
} }
} }
rooms.Unjoin(roomID, channel)
} }
// FindAndUpdatePendingSigner is a utility function to return the state of current signers readiness. // FindAndUpdatePendingSigner is a utility function to return the state of current signers readiness.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment