I am not sure how to describe this problem. And it is likely NOT a nim problem.
I am using a web browser as a UI for a nim program. Since I need to expose the request/response loop, I have written a quick&dirty server into the nim program using the net module.
This is working well when google-chrome or chromium is the browser. It is kind-of okay for Opera. However firefox 41.0.2 seems to cause a client socket disconnect soon after the socket.acceptAddr(...) call. This can be detected by a socket.readLine() returning "" and somewhat fixed by calling socket.acceptAddr(...) again. However the firefox browser is unaware that the client socket disconnected until firefox times out. This can be modulated using the network.http.keep-alive.timeout setting of the firefox browser. Although its occurrence is somewhat random.
I do not see how the net module could be at fault. Perhaps firefox is sending info in the GET header which needs consideration - the quick&dirty server ignores all headers except for the Content-Length.
This is running on Ubuntu 14.04.3 LTS and Nim Compiler Version 0.13.0
Here are some sample header logs (including the previous successful transaction)
Starting Browser:
/usr/bin/firefox @[-new-window, http://localhost:8080/boxenide.html?html]
--- successful transactions ---
RECEIVED GET html ON /app.css
gotFile /home/james/Programming/nimlang/boxEnglish/src/serverDir/app.css
RESPOND GET html ON /app.css
WITH[body {\x0A\x09margin:0;\x0A\x09/* overflow:hid ... n:4px 0 0 4px; }\x0A]
line#0
================ Possible Client Disconnect
line#0GET /app.js?html HTTP/1.1
line#1 = Host: localhost:8080
line#2 = User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:41.0) Gecko/20100101 Firefox/41.0
line#3 = Accept: */*
line#4 = Accept-Language: en-US,en;q=0.5
line#5 = Accept-Encoding: gzip, deflate
line#6 = Referer: http://localhost:8080/boxenide.html?html
line#7 = Connection: keep-alive
line#8 =
Starting Browser:
/usr/bin/google-chrome-stable @[--disable-popup-blocking, -app=http://localhost:8080/boxenide.html?html]
--- successful transactions ---
RECEIVED GET html ON /app.css
gotFile /home/james/Programming/nimlang/boxEnglish/src/serverDir/app.css
RESPOND GET html ON /app.css
WITH[body {\x0A\x09margin:0;\x0A\x09/* overflow:hid ... n:4px 0 0 4px; }\x0A]
line#0GET /app.js?html HTTP/1.1
line#1 = Host: localhost:8080
line#2 = Connection: keep-alive
line#3 = Accept: */*
line#4 = User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
line#5 = Referer: http://localhost:8080/boxenide.html?html
line#6 = Accept-Encoding: gzip, deflate, sdch
line#7 = Accept-Language: en-US,en;q=0.8
line#8 =
Any suggestions are welcome. Thanks.
I don't currently have an account on GitHub or similar. I would have to email the source code and I don't expect you would want that mess (5.5Kb)
I don't feel comfortable loading down the forum with that much stuff either.
Oh well, thanks anyway.
Dear @dom96
It took a while to pare down the code while keeping the erroneous behavior.
I really do NOT think it is a Nim problem at this point. The misbehavior can be increased by running a lot of extra Firefox web pages concurrently (about 10).
I have placed the 6 files involved under the GitHub Gist description:
Nim App Exposing Firefox Weakness
under my new GitHub account (geezer9). It should be public.
It can take up to 6 or 7 consecutive runs of the app program command:
./app -B=firefox
to expose the
Error: unhandled exception: === Possible Client Disconnect GET html ON /app.css [Exception]
Error. When running chrome, I cannot elicit the same error - although it now gives a similar error when I close the web page - because I cut a lot of logic out of the program.
Perhaps you would be willing to give the guiserver.nim source a quick look and tell me if anything looks problematic - maybe some obvious misunderstanding of the http protocol.
Thanks.
It's likely an HTTP problem, or the fact that you are using blocking sockets. Why don't you simply use asynchttpserver?
I only skimmed your code, but this caught my eye. It's not the correct HTTP header syntax: https://gist.github.com/geezer9/00830687bb6d0928a4e9#file-guiserver-nim-L142 (should be Content-Length: <number>). Take a look at this image https://upload.wikimedia.org/wikipedia/commons/c/c6/Http_request_telnet_ubuntu.png, also the rest of the article on Wikipedia about HTTP. https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
Thanks for your help.
I fixed the Content-Length: <number> problem. I must have looked at it 200 times but did not catch it.
The asynchttpserver did not let me modify the server loop which was needed because the application is a bytecode emulator using a second browser window as its GUI.
I really think it is a Firefox weakness because I was able to hide the problem with the following code:
try:
client.readLine(line,200)
except:
echo("client timeout")
client.close()
return false
in place of just the client.readLine without timeout.
I left the echo in just to satisfy myself that firefox was doing it and chrome was not.
Again, thanks for your help.