REST API: out of nowhere response status code 412

Hi, I’m creating MoinMoin->XWiki migrator and I’m issuing a lot of HTTP PUT requests. Sometimes it’s the same request sent many times (when I test conversion functions). Usually everything works but from time to time one random requests stops and I get

{
   "code":412,
   "contactEmail":null,
   "description":"The precondition given in one or more of the request header fields evaluated to false when it was tested on the server",
   "homeRef":"/",
   "reasonPhrase":"Precondition Failed",
   "uri":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.13"
}

every time I issue it. In the same time other requests, with the same headers but different URL work fine. Nothing useful in Tomcat’s logs.

And here is the most funny thing: when I recreated problematic request in Postman I’ve got the same error message. Then I submitted In Postman a page with empty content and it worked. After this I could submit the original page content and it worked and my migrator started working too. This is so strange. Any ideas what’s going on?

Best regards,
Seweryn Niemiec

I don’t know if this helps at all but I see a 412 on the rest API when the page has been locked. I don’t know if this applies totally in your case but maybe there are requests running in parallel on the same page which means it has been locked by one of the requests? I’m going to be digging into the REST framework so I’ll try to post more info here in case it helps.

I can confirm that at least some of the methods exposed on the REST server side of things expose a flag to say whether to fail or not if the page is locked; with a 412 sent if “fail on locked” is true. That would suggest that some of your requests are overlapping on the same page and the default functionality on the xwiki side of things is to fail if locked. XWiki will also try to merge changes so maybe there’s a case where it’s actually the merge that’s failed rather than the page being considered locked; but I’m just guessing, I’ve not seen/found code that does that.