ITコンサルの日常

ITコンサル会社に勤務する普通のITエンジニアの日常です。

FetchOptions#setDeadlineは正しく動作しない@Google App Engine SDK for Java1.3.5。

フィードを読んで、フィードを吐き出すっていうのをGAE/Jでやっているときに、
フィードの読み込みで時間がかかると、タイムアウトエラーを吐き出すという事象に遭遇しました。
フィードを読むところのソースはこんな感じ。

		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		dbf.setNamespaceAware(true); // おまじない?
		DocumentBuilder db = dbf.newDocumentBuilder();
		Document d = db.parse(srcFeedURL);

スタックトレースはこんな感じ。

Uncaught exception from servlet
java.io.IOException: Timeout while fetching: http://d.hatena.ne.jp/Sikushima/rss
	at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:108)
	at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:39)
	at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:404)
	at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:283)
	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
	at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

で、タイムアウトの設定とかないの?
という当然の疑問に行き着くわけですが、
それがタイトルの
com.google.appengine.api.urlfetch.FetchOptions#setDeadline
なわけです。いわゆる低レベルAPIというやつです。


が、しかし、これがいくつを設定しても、
5秒(デフォルト値)でタイムアウトしてしまうのですよね。


ググったら、
Issue 1559 - googleappengine - Cannot increase Java URLFetch deadline - Project Hosting on Google Code
で、

This works for me.

とか言ってるんだけど、動かない。気のせいじゃね?


で、いらいらして

とかつぶやいていたら、
@senzogawaさんが助けてくれて、
既にIssuesにあがってますよ。とのことでした。


Issue 3371 - googleappengine - URLFetch 5 second timeout makes access to Spreadsheets feed impossible - Project Hosting on Google Code


まだ(今後も?)大したことはしてなかった(出来なかった)ので、
バグってなさそうなPython版で書き直しました。
同じアプリケーションIDにJavaPythonもデプロイ出来る
とは聞いてましたが、なんか気持ち悪いですね。。


で、Pythonに移植したわけですが、
deadlineってデフォルトは5秒なんですが、最大でも10秒までしか設定出来ないそうです。

うーん、しょぼいなと。


まあ、10秒以内に取れないフィードなんて、
今のところ、#librahackで有名な
http://d.hatena.ne.jp/Sikushima/rss
だけですけどね。
なんでこんなに重いんだろう。。