r52190 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r52189 | r52190 (on ViewVC) | r52191 >
Date:08:10, 20 June 2009
Author:catrope
Status:reverted (Comments)
Tags:api 
Comment:API: Return HTTP 503 status code on maxlag error, like index.php does
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/api/ApiMain.php
===================================================================
--- trunk/phase3/includes/api/ApiMain.php	(revision 52189)
+++ trunk/phase3/includes/api/ApiMain.php	(revision 52190)
@@ -378,11 +378,10 @@
 			if ( $lag > $maxLag ) {
 				header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
 				header( 'X-Database-Lag: ' . intval( $lag ) );
-				// XXX: should we return a 503 HTTP error code like wfMaxlagError() does?
 				if( $wgShowHostnames ) {
-					$this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag' );
+					$this->dieUsage( "Waiting for $host: $lag seconds lagged", 'maxlag', 503 );
 				} else {
-					$this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag' );
+					$this->dieUsage( "Waiting for a database server: $lag seconds lagged", 'maxlag', 503 );
 				}
 				return;
 			}
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 52189)
+++ trunk/phase3/RELEASE-NOTES	(revision 52190)
@@ -225,6 +225,7 @@
 * (bug 18785) Add siprop=languages to meta=siteinfo
 * (bug 14200) Added user and excludeuser parameters to list=watchlist and
   list=recentchanges
+* Return HTTP 503 status code on maxlag error, like index.php does
 
 === Languages updated in 1.16 ===
 

Follow-up revisions

RevisionCommit summaryAuthorDate
r53353Revert r52190 ("Return HTTP 503 on API maxlag error"): announcement prompted man...catrope08:04, 16 July 2009

Comments

#Comment by Mr.Z-man (Talk | contribs)   15:14, 20 June 2009

Note that this could be a breaking change for some clients. Python urllib/urllib2 for example raises an exception on 503 errors by default.

#Comment by Catrope (Talk | contribs)   15:18, 20 June 2009

Good point, I'll announce it on the mailing list.

#Comment by Anomie (Talk | contribs)   17:20, 30 June 2009

Don't forget to send that announcement. Unless our IRC conversation a few days ago changed your mind. ;)

For anyone else: While this change makes sense from one viewpoint, it doesn't from what is IMO a better view. index.php returns 503 because in the HTTP protocol that's how you indicate an error. But the API isn't HTTP, it just uses HTTP as a transport and reports its errors inside a successful HTTP response. This change basically raises API maxlag from "normal API error" to "transport-layer error", which could be considered equivalent to index.php sending an ICMP error on maxlag.

#Comment by R'n'B (Talk | contribs)   13:59, 15 July 2009

I still haven't seen any announcement of this on the mailing list. Besides knowing that maxlag will throw an HTTP 503 status code, it would be helpful to know what the content of the message body will be, so that this can be distinguished from other 503 conditions (squid errors).

Status & tagging log

  • 08:07, 16 July 2009 Catrope (Talk | contribs) changed the status of r52190 [removed: new added: reverted]
  • 08:11, 20 June 2009 Catrope (Talk | contribs) changed the tags for r52190 [added: api]
Views
Toolbox