Http Statuscode when waiting for lock-release takes to long? -
i using lock mechanism make sure 2 parallel calls not update same row causing unexpected behavior. code this: (no real world example)
public class usercontroller { public actionresult addreputation(int id, int repamount) { int lockwait=0; bool alreadylocked=true; while (alreadylocked) { alreadylocked=getlockforuser(id); thread.wait(1000); lockwait++; if (lockwait>10) { return new httpstatus(xxx); } } setlockforuser(id); adduserrep(id,repamount); return new content("well done"); } }
so. if after 10 seconds lock still exists, want tell caller "please try again later, else saving data user".
what best http-code in rest-api that? 409 conflict
? or 423 locked
?
note: no sql-db. got no real transaction-mechanisms can use. have implement own locking mechanism.
you should ask yourself: client want in situation?
from description, sounds client’s choice wait , try again later. 503 (service unavailable) seems fit:
indicates server unable handle request due temporary overload or scheduled maintenance, alleviated after delay
also, generic 500 (internal server error) @ service.
423 (locked) may or may not fit. designed part of webdav’s locking mechanisms, clients explicitly lock , unlock resources. generally, clients more understand 503 error (very common in wild) 423 error (uncommon outside of webdav): 423 treated generic client error, may not helpful. said, the definition of 423 itself not require webdav locking involved. if want distinguish situation server downtime (which result in 503), 423 may work.
409 (conflict) not seem fit:
this code used in situations user might able resolve conflict , resubmit request.
Comments
Post a Comment