Socket.io connects to the Java Netty server. If socket.io tries to connect the server while it's down, 404 will be ocurred. So Javascript console says:
http://mylocalhost.com/socket.io/1/?t=1354790544338 - Failed to load resource
After this the socket.io connection dies completely. It won't try to connect again because of that 404...
How should I handle this? I tried to set an interval which would try to connect every five seconds, put the server online, but it won't try to connect because of that error.
After page reload it works normally. Is there a way in socket.io for observing when the server is online again and then connect to it? What could be a proper solution?
I've made sure that the socket.io.js client javscript is loaded correctly, and my understanding of what's happening is this:
socket.io starts handshakes, and socket.socket.connecting is set to true
request to http://mylocalhost.com/socket.io/1/?t=1354790544338 causes 404 because the server is down
this is an error, but socket.socket.connecting remains as true, which causes next reconnect attempts to fail, because it won't try to reconnect if it thinks that it's already trying to reconnect
I've tried calling disconnect() before trying to reconnect, and it sets reconnecting as false, but when there's no connected socket and I call disconnect(), it throws "Cannot call method 'close' of undefined".
What could be a proper solution to get that reconnecting as false, kinda "reset" socket.io to be ready for next connection attempt?
Setting handlers for all of the possible socket.io client errors seemed to fix this problem for me*. That includes:
'connect_error'
'connect_timeout'
'reconnect_error'
'reconnect_failed'
'error'
After a bit of experimenting, the 'error' handler seems to be the important one for preventing the 404 from stopping everything else.
*seemed to fix, because I can't reliably reproduce it in my local test setup. Would be good to know if adding these handlers fixes the problem for anyone else.
The socket.io file it tries to request contains actual script to use in JS. This file is served by your Java server. So when you request this file - it will fail to load, that is why you see 404 error.
Since file is not loaded, anything related to sockets that comes from that file wont be available.
So what you want to try to do, is to catch scenario when script file is not loaded. Check here: load scripts asynchronously
So you have to try to load this script asynchronously, and check on status after load. If it failed or did not responded in time - flush request handle, and request again after some delay.
Once file will be successfully loaded, you can start using JS functions to call connect and so on.
Related
Essentially the problem is that BrowserSync isn't "syncing" until after I change a file for the first time, thus the first "refresh" doesn't come for free.
Background:
I'm setting up a very simple repository where we have a gulp process that generates static files to be served by browserSync. Gulp watches those files, and when they change causes browserSync to reload.
Even though the index page serves seemingly fine, the automatic refresh does not work until AFTER you've both changed a watched file for the first time and then refreshed the browser manually.
I've confirmed this by watching the network tab in Chrome's developer tools, and can see that on first load, there is no websocket present until I manually change a file. Then, after I refresh the browser I can see a proper websocket running. It doesn't matter how many times you refresh the page before you change a file, the websocket will simply not initialize.
I've asked in the BrowserSync slack, checked their issues and read the source code and still can't figure out why this is happening.
If needed I can update the question with the relevant parts of my various related files:
Dockerfile
docker-compose.yml
gulpfule.js
I created a screencast gif, but the whole thing is about 20mb - so I didn't upload it.
Thanks in advance for any help.
BrowserSync in terminal on first load:
Network tab on first load - no websocket:
After I change a file:
Network tab after first changed file - with websocket:
Solved
I created a loader.html with a simple javascript that would do a pre-flight request against my local docker IP/port (3000) associated with my BrowserSync project. On the catch, I would just let it loop every 1000ms and on success, I would redirect.
This is where the problem was introduced.
I was doing the pre-flight request on the same IP/port that I was redirecting to, and for some reason the "websocket" was getting "cached" from my pre-flight check and then wouldn't re-initialize on the redirect or any subsequent refreshes.
My solution was to pre-flight check for BrowserSync's UI port which is 3001 not 3000. Once that was up, I could redirect to the IP:3000 without any problems.
I have this weird issue in my django application. I am using the admin interface. When I try to load the change page it doesn't render completely and when i see in logs it says:
**uwsgi_response_write_body_do(): Broken pipe [core/writer.c line 248]
IOError: write error**
The page has been working fine before and suddenly this started happening. And also the behavior is inconsistent. If I reload the page multiple times, few times it renders correctly. This issue is happening in production environment and I am not able to replicate it on my local. The production server is using uwsgi 1.9.10 with nginx and django 1.5. Also I am writing custom HTML on page and there is an inline table also on the same page.
Please let me know if anyone knows why it is happening...
that error means the client (browser) disconnected before getting the full response. Check your webserver logs, maybe you hit a timeout
I encountered strange behavior of an JBoss AS 7 on linux server. When I deploy war with my application, the server doesn't respond for valid HTTP requests for this app. When I try to GET a valid URL, I can see in logs, that backend functions (e.g. DAO methods) are called, debug logs shows that subsequent tags in my JSF are rendered, I even can see a message Rendering View index.xml, but the response never reaches the client.
When I use a non-existent URL (e.g. index.asd) response is 404 and when I use a wrong page name (e.g. inswxasd.xhtml) the response is 500. Thus it fails only with valid requests.
I tried to connect both remotely (using firefox) and locally (with wget) and I reproduced the problem. The strange thing is that I deploy the war that I already used and then it worked.
EDIT 1:
I've just noticed that when I send a request to, the server process takes 200% of CPU. Additionally it happens for only one application with stack: Hibernate, Spring, JSF 2.0, Primefaces.
EDIT 2:
Here is pastie with jstack output (jstack -l -F <PID>). All threads are blocked.
Additionally I noticed (using top and dumping stack of the JBoss process) that the problem is most probably caused by a thread called http--0.0.0.0-8080-1. Any ideas?
Thanks for help. I reverted the database to previous state, and it started to work. Apparently there was a problem in the data that caused this infinite loop. Now we need to find it, but as it is reproducible, I'll manage.
I am developing VAADIN using Db4O for storage. Normally, I love the fact that I can change the source code, save it, and voi-lá: the server gets automatically restarted and I can see the changes in the browser.
But always when I restart the tomcat server I get a DatabaseFileLockedException. My workaround is to stop the server, and start it again. But doing this manually every 1 minute is annoying.
INFO:
I am using the client server configuration, but the VAADIN application itself is the DB4O server (other applications get connected to it):
ServerConfiguration serverConfig = Db4oClientServer.newServerConfiguration();
//Configure server...
ObjectServer server = Db4oClientServer.openServer(serverConfig, DBFILE, PORT);
server.grantAccess(...); //GRANT ACCESS TO OTHER APPLICATIONS
//LOCAL USE ONLY:
private ObjectContainer client = server.openClient();
//PS.: I never close the client locally. Can that be a problem?
Does someone know how to get rid of this?
Thanks in advance.
Hmm, do you even close the server. Otherwise the db4o server will keep running and produce this exception.
Is there some 'shutdown'-callback in VAADIN? Thats usually the place to close the db4o server. When you close the server all local and remote client connections will be shut down aswell or will throw an exception when accessing them the next time.
The program starts correctly if I double-click it or if I debug it from VS2010, but it doesn't respond when I try running it from Services.msc. It used to work just fine, but I tried to un-register and then re-register the service to fix a different bug and now I get the following error:
Could not start the PFAdapterMng service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.
I tried putting logs at the beginning of main(), and I found out that the service stops responding before it even gets there.
I've tried using Procmon to figure out if there's some registry key missing, but I couldn't find any problems through Procmon.
I've also tried re-registering the service to try to fix it, since re-registering the service was what caused the error in the first place. It doesn't seem to fix anything either.
I've stepped through the program with the parameters -UnregServer and -Service to ensure that the program was being unregistered and registered successfully, and it looks like it's being registered as a service correctly.
Is this because of some error in the registry? I don't see how or why my program stops responding before it even gets to main().
What else could I try to do to debug this problem?
UPDATE:
So, I tried un-registering the service after trying to run it, and it seemed to work fine. I look in services.msc, and I still see that the application is a service. In the past, before I got error 1053, it would just disappear after the first time. I tried un-registering it again, and I got a message box:
Service could not be deleted
So I decided to run the application with the parameter -UnregServer inside of Visual Studio 2010 to figure out what the error is. The function DeleteService() is failing with the error:
ERROR_SERVICE_MARKED_FOR_DELETE
The service is not removed until all open handles to the service have been closed. I stepped through the calls to the CloseServiceHandle() function and it seems like the handles were closed successfully. The service is also not removed if the service is running. I checked Process Manager, and the service was not running. Is the service not being removed because the service stopped responding earlier?
I tried restarting my computer and it was gone. Still, I don't understand why I have to restart my computer when the service used to un-register without the need of a restart before I was getting error 1053. Unless of course I can't un-register the service because the service was not stopped because it stopped responding.
I'll keep trying some more things, but I'm running out of ideas.
UPDATE2:
I tried rebuilding the original application, which I know worked as a service. This means the problem is not related to any of my code. Something is messed up with the Services Control Manager. I don't understand why I only get this error with this application. I have another application which communicates with this application which also needs to be registered as a service. I have no problems with that application. It works perfectly.
But for some reason, this application just stopped responding all of a sudden. I don't know what I changed or broke to cause the service to hang before it even gets to my main() function. The only thing I can think of now to fix the problem is to reformat the server, which is not an option.
Thanks,
Krzys
I feel stupid.
I've been using Remote Desktop Connection to connect to this server. Well, the service is starting and erroring out. The reason I didn't see any errors or message boxes was because they were appearing on the console session. I was not connected to the console session. I connected to the server using:
mstsc.exe /admin
And now I can see where the program stops responding.
Feels great to waste 10 hours though.