Skip to content

Commit 9641aca

Browse files
magik6krvagg
authored andcommitted
fix: yield in PSClientPoll correctly (#601)
* fix: yield in PSClientPoll correctly * fix build * pspoll: Don't timeout the context
1 parent 634054c commit 9641aca

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

cmd/curio/debug-proofsvc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ var proofsvcStatusCmd = &cli.Command{
202202
if err != nil {
203203
return err
204204
}
205-
resp, err := proofsvc.GetProofStatus(rcid)
205+
resp, err := proofsvc.GetProofStatus(context.Background(), rcid)
206206
if err != nil {
207207
return err
208208
}

lib/proofsvc/clientctl.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ func RequestProof(request common.ProofRequest) (bool, error) {
249249
}
250250

251251
// GetProofStatus checks the status of a proof request by ID
252-
func GetProofStatus(requestCid cid.Cid) (common.ProofResponse, error) {
252+
func GetProofStatus(ctx context.Context, requestCid cid.Cid) (common.ProofResponse, error) {
253253
start := time.Now()
254254
defer recordClientctlDuration("GetProofStatus", start)
255-
ctx, cancel := context.WithTimeout(context.Background(), MaxRetryTime)
255+
ctx, cancel := context.WithTimeout(ctx, MaxRetryTime)
256256
defer cancel()
257257

258258
return retryWithBackoff(ctx, func() (common.ProofResponse, error) {
@@ -296,7 +296,7 @@ func WaitForProof(request common.ProofRequest) ([]byte, error) {
296296
start := time.Now()
297297
defer recordClientctlDuration("WaitForProof", start)
298298
// Wait for the proof
299-
proofResp, err := GetProofStatus(request.Data)
299+
proofResp, err := GetProofStatus(context.Background(), request.Data)
300300
if err != nil {
301301
return nil, xerrors.Errorf("failed to get proof: %w", err)
302302
}

tasks/proofshare/task_client_poll.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ func (t *TaskClientPoll) CanAccept(ids []harmonytask.TaskID, engine *harmonytask
127127

128128
// Do implements harmonytask.TaskInterface.
129129
func (t *TaskClientPoll) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done bool, err error) {
130-
ctx := context.Background()
130+
ctx, cancel := context.WithCancel(context.Background())
131+
defer cancel()
131132

132133
var clientRequest ClientRequest
133134
err = t.db.QueryRow(ctx, `
@@ -148,10 +149,28 @@ func (t *TaskClientPoll) Do(taskID harmonytask.TaskID, stillOwned func() bool) (
148149
return false, nil
149150
}
150151

152+
pollCtx, ownedCancel := context.WithCancel(ctx)
153+
go func() {
154+
const pollInterval = 10 * time.Second
155+
defer ownedCancel()
156+
157+
for {
158+
select {
159+
case <-ctx.Done():
160+
return
161+
case <-time.After(pollInterval):
162+
if !stillOwned() {
163+
// close the owned context
164+
return
165+
}
166+
}
167+
}
168+
}()
169+
151170
var proof []byte
152171
for {
153172
var stateChanged bool
154-
stateChanged, proof, err = pollForProof(ctx, t.db, taskID, &clientRequest)
173+
stateChanged, proof, err = pollForProof(pollCtx, t.db, taskID, &clientRequest)
155174
if err != nil {
156175
return false, xerrors.Errorf("failed to poll for proof: %w", err)
157176
}
@@ -224,7 +243,7 @@ func pollForProof(ctx context.Context, db *harmonydb.DB, taskID harmonytask.Task
224243
}
225244

226245
// Get proof status by CID
227-
proofResp, err := proofsvc.GetProofStatus(requestCid)
246+
proofResp, err := proofsvc.GetProofStatus(ctx, requestCid)
228247
if err != nil || proofResp.Proof == nil {
229248
log.Infow("proof not ready", "taskID", taskID, "spID", clientRequest.SpID, "sectorNumber", clientRequest.SectorNumber)
230249
// Not ready yet, continue polling

0 commit comments

Comments
 (0)