Getting 504 Gateway timeout and JSONParseException

Questions about the WURFL Cloud service.
clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Tue Dec 02, 2014 3:31 pm

Hello,

I've been running into issues with the WURFL cloud client where api.wurflcloud.com returns:

Code: Select all

< h t m l > < b o d y > < h 1 > 5 0 4   G a t e w a y   T i m e - o u t < / h 1 > 
 T h e   s e r v e r   d i d n ' t   r e s p o n d   i n   t i m e . 
 < / b o d y > < / h t m l > 
This wasn't apparent until I started to debug the code. This caused the JSON library to fail to parse the response.
The message I receive is com.scientiamobile.wurflcloud.exc.UnreachableServerException: There is no possibility to answer. Probably the Cloud Service is unreachable, or you don't have required authorization to access it

I have no issues pinging api.wurflcloud.com - any idea where I should be looking?

Any help would be greatly appreciated.
Thanks!
Clement

Elliotfehr

Re: Getting 504 Gateway timeout and JSONParseException

Postby Elliotfehr » Tue Dec 02, 2014 4:24 pm

Clement,

Are you able to provide me with a sample of your code to try and debug this further? Are you also able to let me know if this error is occurring on your local machine or a production server?

Thank you,

Elliot

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Tue Dec 02, 2014 4:52 pm

Hi Elliotfehr,

We have several environments. I'm using a free account at the moment. I think I've seen similar logs in production as well as development and QA environments (for sure development environment).

As for code snippet:

(Please ignore the log lines... psuedo code because we use our in house lib)

Code: Select all

try
		{
			CloudClientLoader loader = new CloudClientLoader(strAPIKey);
			m_manager = loader.getClientManager();
			if (m_manager.testCallWurflCloud())
			{
				log("Cloud service test returned true.");
			}
			else
			{
				log("Cloud service test returned false and may not be available.");
			}
		}
		catch (Exception e)
		{
			log("Failed to instantiate CloudClientLoader and ICloudClientManager");
		}
This is the line that throws the exception:

Code: Select all

		AbstractDevice device = m_manager.getDeviceFromRequest(request,
				response);
EDIT: request and response types - HttpServletRequest, HttpServletResponse

We've had a license for several years now (west.com) and I've never really looked into it until now (this issue existed but not as frequent as it is now). I don't really see how the client side could be wrong? Since a response was generated by the wurflcloud server?

Thanks for looking into this,
Clement

Elliotfehr

Re: Getting 504 Gateway timeout and JSONParseException

Postby Elliotfehr » Tue Dec 02, 2014 5:11 pm

Clement,

Are you also able to provide me with the location of your servers as well as the frequency that the error is occurring?

Thank you,

Elliot

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Tue Dec 02, 2014 5:20 pm

Hi Elliot,

The server should be from Toronto.
As for frequency, so far I have not been able to make a successful request from my development environment.
I've only made a few requests though.

It might be possible that it is something internal to us - although it would be nice to be able to verify that you guys will not return a 504 in the format I had posted before.

Thanks,
Clement

Elliotfehr

Re: Getting 504 Gateway timeout and JSONParseException

Postby Elliotfehr » Wed Dec 03, 2014 11:12 am

Clement,

Are you able to post the response headers that you receive using the curl command below?

curl -i -u YOUR_API_KEY -A "WurflCloudTest/1" "http://api.wurflcloud.com/v1/json"

Thank you,

Elliot

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Wed Dec 03, 2014 12:13 pm

Hello Elliot,

Here's the response from CURL

HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Wed, 03 Dec 2014 16:46:35 GMT
Content-Type: application/json
Connection: close
X-Powered-By: HHVM/3.2.0
Cache-Control: no-cache, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT

{"apiVersion":"WurflCloud 1.5.0.2","mtime":1414773789,"id":"generic","capabiliti
es":{"model_name":"","is_smartphone":false,"is_tablet":false,"is_wireless_device
":false,"mobile_browser":""},"errors":{}}

Everything looks fine... strange. I'm going to run a Wireshark capture to see what is going on. Thanks for the help Elliot.

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Wed Dec 03, 2014 1:31 pm

Hi Elliot,

I've captured the TCP stream through Wireshark - does anything stand out to you as problematic?
I wonder if anything from the header can cause a rejection on your end (It appears that the 504 response is coming from 50.57.185.227

I've removed some of the data just in case...

Code: Select all

GET /v1/json/search:('') HTTP/1.1

host: some server

connection: Close

content-length: 57

cache-control: no-cache, no-store

origin: some server

user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36

content-type: application/x-www-form-urlencoded; charset=UTF-8

accept: */*

x-prototype-version: 1.6.1

x-requested-with: XMLHttpRequest

if-modified-since: 0

dnt: 1

referer: some web page

accept-encoding: gzip

accept-language: en-US,en;q=0.8,ja;q=0.6,fr;q=0.4,nl;q=0.2,ko;q=0.2,zh-CN;q=0.2,zh;q=0.2,zh-TW;q=0.2,pt;q=0.2,es;q=0.2,it;q=0.2,de;q=0.2,ru;q=0.2

cookie: useraction=%20; authToken=token; PartMeetingNumber=stormrage; fbm_231094447012733=base_domain=some domain; fbsr_231094447012733=cDTUaTONPLpVGxpQf11RQJoT9sUzKcCLUeSdRdME2H8.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImNvZGUiOiJBUUJ0c2RlaE8zWVNqOXlmaUJDS0o5RmJrcVZwM2Q1YUppVTVjNmdoV01kbE5GdlhYNC12RFg5b21wVnZidUZIbEo4SXBtZWdNaUs4d3hLc09KcjVOZjJwSTVJcU42Mm9nLS1zekszOEZ0ekxKaEdDdjNKT2NwbG9ZTDZudHdGUHRiSk5IN2t5ZklaX0dLNDJJa2FWemU5c0FzUHpfMWFrNXk2MXo0ZlZVT2pOUURlNThLZjlRLVNVclRUdHgwckQzeTJvaGZyejBIbDRiUlAtT3F5UUF3MDh0SjBiZHVZaEU2Z0MtNi1lX3VMZG81N3JSTzNpMEpfQUp6cWpYaC10QmdBUFZBUGs1ZElBTTBGYlB0c3FERzUxTDIwSkZtQVdrUlpVbk92UDJTRGdpRTM2MkxjWmJaeVc2ak9YVDBvMEhVX1kxcDVSN0l2Umh5U0psS2JTdGw0VCIsImlzc3VlZF9hdCI6MTQxNzYyNjE2MSwidXNlcl9pZCI6IjUwODUyNjUyMCJ9; pid=Tvl3J1CHLKSwDyXWvyh3w5hvfHRmMM4QvxnyQrbQDhktgzXjH; JSESSIONID=some id

X-Forwarded-For: some ip

X-Cloud-Client: WurflCloudClient/Java_1.0

Authorization: Basic abcd1234



HTTP/1.0 504 Gateway Time-out

Cache-Control: no-cache

Connection: close

Content-Type: text/html



<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>
EDIT: I also see the count for detection go up while I receive the 504 response.

Thank you for your help and patience.
Clement

kamermans
Posts: 393
Joined: Mon Jun 06, 2011 9:50 am

Re: Getting 504 Gateway timeout and JSONParseException

Postby kamermans » Wed Dec 03, 2014 4:24 pm

Thanks for sending the HTTP headers. We were able to reproduce the issue locally.

The problem is that the Java client is sending the "content-length: 57" header, which is instructing our load balancers to wait to dispatch the request until all 57 bytes have been received, however, there is no body content since this is a GET request, so the load balancers sit and wait for you to finish sending content, then timeout after 5 seconds.

We are not yet sure if this is a systemic problem with our cloud client, or something is happening in your environment to cause this, but we will certainly try to reproduce it with the Java Cloud Client itself.
Thanks,

Steve Kamerman
ScientiaMobile

Make sure you check out our WURFL Cloud, WURFL InSight and WURFL InFuze products!

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Wed Dec 03, 2014 4:41 pm

Thanks Steve,

Any workaround?

Thanks,
Clement

kamermans
Posts: 393
Joined: Mon Jun 06, 2011 9:50 am

Re: Getting 504 Gateway timeout and JSONParseException

Postby kamermans » Wed Dec 03, 2014 4:46 pm

If you have access to the XMLHttpRequest object, maybe you could clear the content-length header before the request goes out.

We don't seem to have any other people that are experiencing this problem - I only see 8 requests in North America yesterday (all from allstream.net), so perhaps it's something in your environment, like a specific Java version, that is causing it?
Thanks,

Steve Kamerman
ScientiaMobile

Make sure you check out our WURFL Cloud, WURFL InSight and WURFL InFuze products!

Elliotfehr

Re: Getting 504 Gateway timeout and JSONParseException

Postby Elliotfehr » Wed Dec 03, 2014 5:12 pm

Clement,

From what I can tell, the Java cloud client does not send several of the headers that are included in you request, such as the x-prototype-version and content-length headers. Do you know what might be adding these headers into the request in your environment?

Thank you,

Elliot

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Thu Dec 04, 2014 11:57 am

Hi Elliot, Steve,

I'm simply passing the incoming HttpServletRequest through to the cloud client. The request being passed is a request that our application would serve, but we'd like to know if we need to drive a mobile workflow as opposed to a desktop workflow.

I've looked into clearing the content-length but to no avail. The strange thing is that this implementation has always been this way. I cannot say for sure when we started to encounter this problem.

Perhaps something was changed on our end. I will continue to investigate. Thank you for your help.

EDIT: It looks like the request leading up to the call to the cloud client is a POST with some POST data (hence the content length). This is a change that we've made recently and would explain the problem. Is there a way for this to work?

Thanks,
Clement

Elliotfehr

Re: Getting 504 Gateway timeout and JSONParseException

Postby Elliotfehr » Thu Dec 04, 2014 5:22 pm

Clement,

We will be creating a patch to the Java cloud client to prevent this issue from occurring and will let you know as soon as it is available.

Thank you,

Elliot

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Thu Dec 04, 2014 5:44 pm

Thank you so much!!

This was really helpful :D

Clement

Elliotfehr

Re: Getting 504 Gateway timeout and JSONParseException

Postby Elliotfehr » Mon Dec 08, 2014 10:24 am

Clement,

I have just uploaded an updated cloud client to your file manager on scientiamobile.com. Are you able to confirm if the issue is persisting with this update?

Thank you,

Elliot

clementchiu
Posts: 9
Joined: Tue Dec 02, 2014 3:24 pm

Re: Getting 504 Gateway timeout and JSONParseException

Postby clementchiu » Mon Dec 08, 2014 1:31 pm

Hi Elliot,

I'm able to perform a detection with the build you provided me.
Thank you so much for all your help!

Clement


Who is online

Users browsing this forum: No registered users and 12 guests