Push Chains & TRC in sync instead of async
We saw many problems during tests. As a next step we will also add ACKs and wait until we received the ACk.
(See also
@@ -263,25 +263,20 @@ func (store *Store) insertTRCHookForwarding(ctx context.Context, trcObj *trc.TRC
if err := store.insertTRCHookLocal(ctx, trcObj); err != nil {
return err
}
- go func() {
- defer log.LogPanicAndExit()
addr, err := store.ChooseServer(ctx, store.ia)
if err != nil {
- log.Error("Failed to select server to forward TRC", "err", err)
+ return common.NewBasicError("Failed to select server to forward TRC", err)
}
rawTRC, err := trcObj.Compress()
if err != nil {
- log.Error("Failed to compress TRC for forwarding", "err", err)
+ return common.NewBasicError("Failed to compress TRC for forwarding", err)
}
- forwardCtx, cancelF := context.WithTimeout(context.Background(), 5*time.Second)
- defer cancelF()
- err = store.msger.SendTRC(forwardCtx, &cert_mgmt.TRC{
+ err = store.msger.SendTRC(ctx, &cert_mgmt.TRC{
RawTRC: rawTRC,
}, addr, messenger.NextId())
if err != nil {
- log.Error("Failed to forward TRC", "err", err)
+ return common.NewBasicError("Failed to forward TRC", err)
}
- }()
return nil
}
@@ -396,26 +391,20 @@ func (store *Store) newChainValidatorForwarding(validator *trc.TRC) ValidateChai
if err != nil {
return common.NewBasicError("Unable to store CertChain in database", err)
}
- // forward to local CS, async
- go func() {
- defer log.LogPanicAndExit()
addr, err := store.ChooseServer(ctx, store.ia)
if err != nil {
- log.Error("Failed to select server to forward cert chain", "err", err)
+ return common.NewBasicError("Failed to select server to forward cert chain", err)
}
rawChain, err := chain.Compress()
if err != nil {
- log.Error("Failed to compress chain for forwarding", "err", err)
+ return common.NewBasicError("Failed to compress chain for forwarding", err)
}
- forwardCtx, cancelF := context.WithTimeout(context.Background(), 5*time.Second)
- defer cancelF()
- err = store.msger.SendCertChain(forwardCtx, &cert_mgmt.Chain{
+ err = store.msger.SendCertChain(ctx, &cert_mgmt.Chain{
RawChain: rawChain,
}, addr, messenger.NextId())
if err != nil {
- log.Error("Failed to forward cert chain", "err", err, "chain", chain)
+ return common.NewBasicError("Failed to forward cert chain", err, "chain", chain)
}
- }()
return nil
}
}
