Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network connection lost reported by iOS clients. #487

Closed
rolivieri opened this issue May 19, 2016 · 5 comments
Closed

Network connection lost reported by iOS clients. #487

rolivieri opened this issue May 19, 2016 · 5 comments
Milestone

Comments

@rolivieri
Copy link
Contributor

rolivieri commented May 19, 2016

Description of the problem will be added below.

@rolivieri rolivieri changed the title Broken pipe issue - credentials middleware. Network connection lost reported by iOS clients. May 20, 2016
@rolivieri
Copy link
Contributor Author

Long story short, 1) if the body of an HTTP request from an iOS client to a Kitura-based server app has a semi-large amount of data (e.g. ~600kb), 2) and the body of that HTTP request is not consumed (i.e. read) at all on the Kitura-based server, 3) and a response is sent to the iOS client, 4) then a network connect lost or a network timed out error is reported by the iOS application. Now if the body of the http request is consumed and, only after that, a response is sent to the iOS app, then no errors are reported on the iOS side.

I can now reproduce this easily and have code to demonstrate this issue if needed. The question now seems to be: What changes are needed in Kitura so that a response can be sent to a client without having to consume the body of the http request? Not being able to send a response without having to consume the body of the request is having a negative impact on the MCA Server SDK and also on any Kitura-based application that needs to send a response without having to consume the HTTP request body (~ >600kb).

@irar2
Copy link
Contributor

irar2 commented May 23, 2016

I can't reproduce the problem. I sent an almost 2MB picture with wrong token, and got an error from the server, but no connection lost/network timeout. Could you please provide more information how to reproduce this?

@rolivieri
Copy link
Contributor Author

rolivieri commented May 23, 2016

@irar2 - The easiest way to reproduce this problem is to clone the following branch: git clone -b ro-test2 https://github.com/IBM-Swift/BluePic.git. Once you've cloned the repo, compile both, the iOS app (BluePic-iOS) and the server side code (BluePic-Server). Dome that, add breakpoints to the iOS app in the following file: BluePic/DataManagers/BluemixDataManager.swift. You may want add breakpoints to the rotest() method, specifically lines 518, 534, 535. Also, make sure you reset your iOS simulator so that it is at known state. Now, launch the BluePic server (.build/debug/Server) and then launch/run the iOS app. Sign in using your Facebook account. Done that, then try to upload a picture from the camera roll in the simulator. This action will take you to the rotest() method and your breakpoints should be hit. Using the debugger in Xcode, step through lines 535 - 541. You should see that on the server side things seem to be fine but on the client (iOS side) you should see that the error variable is NOT nil and response object is nil.

Once you have reproduced the problem, you can also take the following steps. Go to the following file on the server side: BluePic-Server/ Sources/Server/Routes.swift. Uncomment lines 43 and 44 and rebuild the server:

let rawUserData = try? BodyParser.readBodyData(with: request)
print("rawUserData: \(rawUserData)")

Now, try to upload an image again using the iOS app. Now that you are consuming the request body the error should not occur. In other words, the error object should now be nil and the response object should NOT be nil. You can play with uncommenting and commenting out lines 43 and 44 in the Routes.swift file to reproduce the problem. Let me know if you have any other questions.

irar2 added a commit to Kitura/Kitura-net that referenced this issue May 24, 2016
…end a response while request's body hasn't been read
@irar2
Copy link
Contributor

irar2 commented May 24, 2016

@rolivieri Please validate

@rolivieri
Copy link
Contributor Author

@irar2 Tested the fix and it is working! Thanks for your help.

@dfirsht dfirsht added this to the 0.16 milestone May 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants