In the past I had lots of problems while developing software applications and I am still having them. Here I would like to share one of my experience about client-server communication problem which caused me a lot of trouble until I sorted it out.
It was back in 2011. We were developing an application for a customer. We had released our application and about 150 users started to using it all day long. Our application was working on an Apache Tomcat server. The team reported one bug about uploading file which was working unstable. The problem was that, time to time, users were getting a message like “error” with no explanation while uploading a file just after clicking the upload button. However, it was the kind of an error which we were unsuccessful to generate using a pattern. We definitely had no clue about the reason.
Identifying the problem
As the first step, I tried to generate the error intentionally but I failed. When I changed users to test, the users that were getting error were not getting it anymore while those that didn’t get the error started getting the error. I thought it was about a user related data, kept changing users and clients (computer), but it still had the same problem. I tried to take note about computers and time as far as I could recall. In the end there was no evidence as to why the problem occurred.
We tried to debug the application, but that was not effective because the pages had been developed using JSP techonolgy. We might have tried couple of things but did not lead us to conclusion.
Then I thought it is related with oracle rowid (another struggling experience, the same problem with oracle rowid) and tried to prove it and it resulted as false alarm. After several days and hours I quit searching the problem and only tried to find a workaround solution.
The customer learned how to live with that error.
3 months later, a friend started working with us. He had no experience on developing java applications and I was his mentor. I was advising him to develop some small applications using java related technologies like JSP, Servlet, jdbc etc
One day he asked me about servlets and I said it was better to develop some small POC application so that we could observe results and this would be kind of hands-on training. With the help of universe we selected a JSP script to develop it using servlets which was the page used for upload functionality. While we were playing with the code, we started debugging it. Suddenly, I had realised that session id caused a problem. The session id was meant to be a number but it was not. It had an additional plus (+) character.
Our upload component retrieves session id and sends the data chunks along with it. Our client code fetches session id from the server within the response body and sends it as a query string. If you send a plus character as a query string, you need to make it encoded to avoid undesired results like we had. Your browser will send it as a plus character (+) but when your server gets this query string, it will process it as a space character and will map it with no active session. Then the server will respond with ERROR.
Someone in the company had developed this page years ago and we had the problem with a certain version of tomcat. We developed an interceptor for all http messages and encoded them before sending to the server side and develop another piece of code which confronts the incoming messages and decodes them into normal form. In the end, our problem was solved.