use unique p2p preflight idempotency keys

This commit is contained in:
richjohnrambo
2026-09-27 13:36:12 +08:00
parent 8280ac5987
commit ecfe13ff0e
+5 -4
View File
@@ -216,11 +216,12 @@ type p2pResponse struct {
func (a *apiClient) ensureP2P(ctx context.Context, source, target AccountRecord) (*p2pResponse, error) { func (a *apiClient) ensureP2P(ctx context.Context, source, target AccountRecord) (*p2pResponse, error) {
var result p2pResponse var result p2pResponse
// EnsureP2P is itself idempotent and must execute on every preflight so it // EnsureP2P must execute on every preflight so it can repair subscriptions
// can repair subscriptions and refresh a loaded topic. A stable HTTP // and refresh a loaded topic. Use a fresh key instead of replaying an old
// idempotency key would replay an old response and skip that repair. // successful response from a previous load-test run.
idempotencyKey := fmt.Sprintf("loadtest-p2p-%d-%s-%04d", time.Now().UnixNano(), source.Machine, source.Index)
err := a.do(ctx, http.MethodPost, "/v1/im/conversations/p2p", source.Token, err := a.do(ctx, http.MethodPost, "/v1/im/conversations/p2p", source.Token,
"", idempotencyKey,
map[string]any{"peer_user_id": target.UserID}, &result) map[string]any{"peer_user_id": target.UserID}, &result)
return &result, err return &result, err
} }