Why do I get IOException on nio read from channel before all data is read?

I am working on an NIO based http client library but I've noticed two problems.
#1: I have been testing against an http server that has authentication turned on. Hence, any request that comes its way will respond with a '401 Authentication Required' response. In the case of a POST, I've noticed that this particular http server does not wait for the body to arrive before responding. As soon as it gets the headers, it dumps the 401 response onto the channel and closes the connection. My library then gets an IOException on the next write to the channel even though I've received write interest event. (I'm using non blocking mode)
Whether I get the exception depends on timing. Sometimes, my writes work and the exception is averted. Sometimes not. The longer I delay since the time I get the write interest event, the more likely it is the exception will occur.
Now, in this situation, I really think it's the http server that is violating the http protocol. I give a valid content length that is not zero but it does not wait for me to finish my request. The moment I write the last empty line of the header section, it responds and closes the channel. Even though I don't think this is correct, my library has to deal with it. So in this situation, I've decided my library will abandon the write phase and move on to reading the response.
NOTE: In the majority of cases, a client would have already authenticated by landing on some page that could produce a POST in the first place. However, for technical reasons I can't mention here, I must support the case that the very first (unathenticated) request to the server is a POST.
2) After #1 above occurs, reading from the channel will also throw an IOException but only on Windows. Sometimes I get the headers only, sometimes the whole document, sometimes nothing. Again, the longer I delay reading (since the time I get the read interest event) the more likely it is the exception will be thrown. This NEVER happens on Linux. I always get the full response on Linux after the #1 happens even if I put long delays between reads.
I can understand #1 happening but #2 should not. I can always see the complete response data on the wire using a network protocol analyser. The data is there every time but my library doesn't always get it.
In situation 2, there is nothing I can do. If I don't receive the data, I have to respond with an error even though the request was successful.
I have stripped down my library to the bare essentials and can reproduce the problem in a self-contained environment every time.
Any ideas why the discrepency between Windows/Linux? Does this seem right?

I read through the section you mentioned. I realize the connection may be dropped at any time. Handling this is no problem. It is reported as an exception to the client. However, this situation is different. I still see no provision that allows a server to respond to a half written request. A request is defined to include an optional message body (Section 5). The client dictates whether it is optional, not the server. Furthermore, section 6 clearly states "After receiving and interpreting a request message, a server responds with an HTTP response message.". To me, this implies the server must wait for the entire request before responding even if its a waste of time. This particular server is attempting to short circuit what I see is the required request/response cycle. In doing so, it is causing me some pain in trying to deliver its response since it seems on windows this interferes with my ability to read it.
The simple answer to this is to process reads before writes, i.e. OP_READ before OP_WRITE. I tried this as well. Originally, I was not even registering READ interest while I was writing my request. (I saw no reason to. I don't want to give my client a response while they are writing their request.) But even when I do register READ interest while I'm writing (and process read events before write), the read event still produces no data and no eof (-1) indication on the read. The discrepency between linux and windows is bothering me. No matter what I do, I can't deliver the response even though its written to the channel by my peer. I think I will supply some code and see if anyone can get it to work on windows.Edited by: r2rossi on Sep 24, 2008 10:42 AMEdited by: r2rossi on Sep 24, 2008 10:43 AM
Edited by: r2rossi on Sep 24, 2008 10:45 AM
Edited by: r2rossi on Sep 24, 2008 10:46 AM

Similar Messages

  • Why cant I get a song to sync from my computer to my iphone 4s

    why cant I get a song to sync from my computer to my iphone 4s

    That is vague.
    What have you tried?
    What happened?
    Error message?

  • Why am I getting unable to purchase message from App Store with free apps

    Why am I getting unable to purchase message from App Store for free apps on my I pad?

    Sign out of your Apple ID, reboot yor iPad and sign in again.
    Settings>iTunes and App Store. Tap your ID and sign out.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.
    Go go back to Settings>iTunes & App Store. Sign in. Try to download the free apps again.

  • (Failed to read from channel: -1)

    Hi,
    I get an error Failed to read from channel: -1 when I try and connect to my company server using the Remote Desktop MAC OS X client. It appears that I am actually communicating with my companies server as I did get asked if I recognised
    the security certificate but I get this message shortly after. I can't seem to find anything on it on the Web so could do with some assistance.
    If anyone wants further information or want's me to create a log (and knows how to direct me) then I will do.
    Thanks,
    virka

    Same problem here. I can't figure out why i get this error
    Log file:
    [2014-Apr-16 12:07:59] RDP (0): Protocol state changed to: ProtocolActive(5)
    [2014-Apr-16 12:07:59] RDP (0): Protocol state changed to: ProtocolInactive(4)
    [2014-Apr-16 12:07:59] RDP (0): Server supports RAIL
    [2014-Apr-16 12:08:00] RDP (0): Protocol state changed to: ProtocolActive(5)
    [2014-Apr-16 12:08:42] RDP (0): Server hides cursor
    [2014-Apr-16 12:08:46] RDP (0): Server shows cursor
    [2014-Apr-16 12:11:09] RDP (0): Server hides cursor
    [2014-Apr-16 12:11:13] RDP (0): Server shows cursor
    [2014-Apr-16 12:11:53] RDP (0): Server hides cursor
    [2014-Apr-16 12:11:55] RDP (0): Server shows cursor
    [2014-Apr-16 12:12:09] RDP (0): Server hides cursor
    [2014-Apr-16 12:15:52] RDP (0): Exception caught: Exception in file '../../librdp/rpcoverhttp.cpp' at line 353
        User Message : Failed to read from channel: -1
    [2014-Apr-16 12:15:52] RDP (0): Exception caught: Exception in file '../../librdp/rpcoverhttp.cpp' at line 353
        User Message : Failed to read from channel: -1
    [2014-Apr-16 12:15:52] RDP (0): Protocol state changed to: ProtocolDisconnecting(7)
    [2014-Apr-16 12:15:52] RDP (0): Protocol state changed to: ProtocolDisconnected(8)
    [2014-Apr-16 12:15:52] RDP (0): ------ END ACTIVE CONNECTION ------
    [2014-Apr-16 12:41:29] RDP (0): Final rdp configuration used: gatewayhostname:s: confidencial
    screen mode id:i:2
    use multimon:i:1
    session bpp:i:24
    full address:s:confidencial
    audiomode:i:0
    username:s: confidencial
    disable wallpaper:i:0
    disable full window drag:i:0
    disable menu anims:i:0
    disable themes:i:0
    alternate shell:s:
    shell working directory:s:
    authentication level:i:2
    connect to console:i:0
    gatewayusagemethod:i:1
    disable cursor setting:i:0
    allow font smoothing:i:1
    allow desktop com"font-family:Helvetica;line-height:normal;" />bookmarktype:i:3
    use redirection server name:i:0

  • Why do I get a "script error" message from Adobe flash player?  It is installed as a part of my browser.IE 11

    Why do I get a "script error"  from flash player when it is not installed separately?  It is part of my browser--IE 11

    Same error message, I disabled tab mix and made sure I only have the newest version of Java, restarted firefox, now it seems to be fine no error yet on Pogo games or pictures upload to ebay which were the biggest problems besides hanging. I had also had disabled AVG secure search yesterday but that did not solve the issue. Now I will try to add back in AVG search...I have very few adds ons, also the note embedded about re- installing a toolbar went away, my old one did not work with FF4, so I installed Yahoo toolbar but the message still did not go away until I applied this fix. Hopes this helps someone..

  • I Keep getting sur charges from my newly online purchase of Adobe X1.. I already had to change a Credit Card due to this fact.. Why am I getting individual (small incriment) charges from Adobe.. As on Wells Fargo Statement..??

    Why am I getting small incremental charges from Adobe XI .. I dont wish to keep changing the billing# of 14.99 a month, I would just like to understand the other charges on my account of the same?

    security questions was the least of my issues, hence, it did not make my gripes summary.  the account owner authorized the order over the phone easily, but somehow some way the order still failed to go through.  only one agent, the last agent, stayed on the line while the ToSA was being done  1. to check that she was transferring me to the correct ToSA, 2. to check that the ToSA was successfully completed, and 3. so she could me the confirmation numbers i needed to track it.
    i had difficulties with completing the ToSA, simple required task for an authorized purchase, not once, but TWICE.  the ToSA did not go through on the order on june 3rd for whatever reason.  and when i was transferred to the wrong ToSA line in my own attempt to authorize a purchase on june 5th, i can see this error being replicated numerous times limiting the efficacy of an automated system when agents don't stay on the line to confirm that the final step goes through.  i even tried getting the confirmation number on june 3rd, but when i called, the verizon system is conveniently down rendering any form of follow up useless.  as a consequence, the lack of ability to have a single agent managing the case turns into a telephone game through the documented notes with agents unaware of what has been done previously and the reasons for managing a case a certain way. 
    another huge frustration i didn't highlight in my gripes is that none of this can be resolved in person at a verizon store.  fortunately for those who live next to a corporate verizon building, it is easy.  for the rest of us, it isn't quite so.

  • Read from text file vi won't read file...

    I am very new to LV programming so I hope you forgive any stupid mistakes I am making.   I am using Ver. 8.2 on an XP machine.
    I have a small program that stores small data sets in text files and can update them individually or read and update them all sequentially, sending the data out a USB device.   Currently I am just using two data sets, each in their own small text file.  The delimiter is two commas ",,".
    The program works fine as written when run in the regular programming environment.   I noticed, however, as soon as I built it into a project that the one function where it would read each file sequentially to update both files the read from text file vi would return an empty data set, resulting in blank values being written back into the file.   I read and rewrite the values back to the text file to place the one updated field (price) in it'sproper place.  Each small text file is identified and named with a 4 digit number "ID".   I built it twce, and get the same result.  I also built it into an installer and unfortunately the bug travelled into the installation as well.
    Here is the overall program code in question:
    Here is the reading and parsing subvi:
    If you have any idea at all what could cause this I would really appreciate it!
    Solved!
    Go to Solution.

    Hi Kiauma,
    Dennis beat me to it, but here goes my two cents:
    First of all, it's great to see that you're using error handling - that should make troubleshooting a lot easier.  By any chance, have you observed error 7 when you try to read your files and get an empty data set?  (You've probably seen that error before - it means the file wasn't found)
    If you're seeing that error, the issue probably has something to do with this:
    Relative paths differ in an executable.  This knowledge base document sums it up pretty well. To make matters more confusing, if you ever upgrade to LabVIEW 2009 the whole scheme changes.  Also, because an installer contains the executable, building the installer will always yield the same results.
    Lastly, instead of parsing each set of commas using the "match pattern" function, there's a function called "spreadsheet string to array" (also on the string palette) that does exactly what you're doing, except with one function:
    I hope this is helpful...
    Jim

  • Read from file and plot data against timestamp

    Hello,
    I know that there are already many posts regarding the question I m about to ask. But, I somehow dont seem to achieve what I want using the suggestions given in the other posts.
    My problem is that, I have a file with the first column as a time stamp containing hour, minute, second and millisecond. The second column in a set of pressure values. I want to plot a graph of these pressure values against the timestamp recorded in this .txt file. Whatever I do, the timestamp values seem to skip by a couple of seconds.
    How do i do this correctly?
    Also, Is it advisable to use the read from file or the read from spreadsheet file vi? Kindly help me out.
    Thanks and regards.

    Hey, I was having a similar issue the other day.  The first problem I had was how to open the file and actually get the timestamp information.  Since I'm using LabView 8.0, I had to go into Read Spreadsheet File and create a new vi to open strings (in an array form).  That's the Read Spreadsheet File (string) vi below.  Then, I had to figure out how to convert the string of a timestamp to something meaningful to me.  The Timestamp2.vi is how I did that below.  I'm also including a little test file.  So, to run Timestamp2.vi, you will have to input the right base path, and have the Read Spreadsheet File (string).vi in the same place as Timestamp2.  Hope that helps.  I think I'm finally getting this stuff, so let me know if it doesn't work.
    Attachments:
    Test.txt ‏1 KB
    Timestamp2.vi ‏28 KB
    Read From Spreadsheet File (String).vi ‏25 KB

  • Making the vi faster - read from txt or array or binary reading

    I prepared a vi that reads a table from txt file and find the desired values corresponding independent two variables by interpolation-attached. This via reads the txt file for each calculation. I wonder that is this process slow or enough for me. Becasue I add this via to a daq vi and I send measurement values from this via to the interpolation.vi. I acquired samples once in a sec. Or is this more convenient to read the txt once and after writing values to arrays and use these arrays as a constant (Right click array-->Data Operation-->Make current value default) in the vi? Which one is faster? And also, I wonder that instead of reading from txt file, is it a good way to convert my values in txt to binary data and read this binary values by vi? Last thing, how can I learn a vi program run-spend time?
    Egemen
    Attachments:
    interpolation1.vi ‏20 KB
    interpolation2.vi ‏29 KB
    R600a_bar_P_0,1_sat_refprop_labview.txt ‏20 KB

    nathand wrote:
    newbieeng wrote:
    Last thing, how can I learn a vi program run-spend time?
    Reordering your words a bit... Are you asking how to measure how long it takes to run your VI?  You can do this with a sequence structure (one of the few reasonable uses for them): in the first frame put a "Tick Count" or "Get Date/Time in Seconds" function.  In the next frame put your code.  In the last frame, put the same function that you placed in the first frame.  Subtract the time value in the first frame from the value in the last frame; the difference is the time it took to run your VI in milliseconds or seconds (depending on which time function you used).
    Another option is the VI Profiler, under Tools -> Performance and Memory.  Open that window, click "Start," run your code, and click "Stop."  It will report how much time it took to run your VI along with other timing information.
    Thank you nathand. I am sorry for usage of wrong order. I tried your suggestion and it works great. The first vi takes 4-6 msec. And the second one takes just 0 msec because it does not calculate anything, including just constant values.
    Egemen

  • Dev question: how to prevent Adobe Reader from copying pdfs to "Download/Adobe Reader"?

    I am making an app that downloads pdf files from a server and the users can decide to store them in the phone. Those files are kept in the app's private storage.
    The pdf files can be opened from inside the app. The problem is that every time a pdf is opened, adobe reader copies it in "Download/Adobe Reader" (the path may be different depending on the device and the android version). Those pdf files should not be available from outside my app. How can I prevent adobe reader from creating copies in that folder? Do I really have to make my app track them down and delete them? It wouldn't be the safest solution...
    In order to open the files, I se up a content provider:
    from the manifest:
    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.myapp.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true" >
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths" />
    </provider>
    And then, in a method, I do this:
    File pdfToRead = new File(pdfPath);
    Uri uri = FileProvider.getUriForFile(context, "com.example.myapp.fileprovider", pdfToRead);
    for (ResolveInfo resolveInfo : appsList) {
        String packageName = resolveInfo.activityInfo.packageName;
        context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    openPDF(context, uri);
    public static final void openPDF(Context context, Uri localUri) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setDataAndType(localUri, PDF_MIME_TYPE);
        context.startActivity(i);
    Thanks for the help.

    Meh, I just hoped there was a way to tell acrobat "don't create a copy of the file because it's private". For now, I'm detecting the "downloads/Adobe Reader" folder, look if there's the file that was opened and delete it.
    Now I need to know something that I can't ask on stackoverflow: what paths does Adobe Reader use to create the "Adobe Reader" folder? Because not every device has an external sd card (external, not removable. Just for clarity). In my device it's at "Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/Adobe Reader".

  • Read from the datafile while data acquisition

    I have a program to process and record the data while experimenting. The data file is attached here with (please have a look). It is recorded injection by injection with injection number. Is it possible to read the data file while acquisition and display the injection number (only the injection number)? I mean, the counter should count the number of injection while experiment from the datafile.
    Attachments:
    Test2.txt ‏59 KB

    If you are writing to the file, it is really a bad idea to try to read from it at the same time.  Weird things can happen.
    Instead, you should keep a counter in your code.  Shift Registers work extremely well for that.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Is Read From Spreadshee​t file VI a read only%3F

    I came across the Read From Spreadsheet File VI and wondering if that is a read only?  I am under the impression that it is not because in the Help menu the following is stated:
     The VI opens the file before reading from it and closes it afterwards. You can use this VI to read a spreadsheet file saved in text format. This VI calls the Spreadsheet String to Array function to convert the data.
    I usually use Create/Replace and do a read only so I am wondering if this is read only or read/write when it opens up a file?
    -ncm
    Solved!
    Go to Solution.

    Digging into the VI, I see that it is using Read Only permission for opening and reading the file.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Why do I get this message when logging onto itunes "File Ituneslibrary cannot be read because it was created by a newer versiion of itunes

    Why do I this message when trying to open itunes on my desktop computer "File itunes cannot be read because it was created by a newer version of itunes"  How do I overcome this?   

    Hello johnc1936,
    Thanks for the question, and welcome to Apple Support Communities.
    It sounds like we may need to recreate your iTunes Library.itl file. The following article outlines how to do so:
    iTunes: How to re-create your iTunes library and playlists
    http://support.apple.com/kb/HT1451
    Thanks,
    Matt M.

  • Why do I get an error message while I am setting up iMessage that reads "could not sign in. Please check your network connection and try again." Funny thing is internet Safari works just fine.

    As the subject line. When I try to activate either iMessage or FaceTime I get this error message "Could not sign in. Please check your network connection and try again." Funny thing Safari works just fine with my network connection. The device in question is an iPhone4. iOS 7.06

    The following link has a section for dealing with that error message that may help: http://support.apple.com/kb/TS4268

  • Why do i get a usb power warning from my retina display macbook pro?

    When home, i connect my 13" retina macbook pro to my thunderbolt monitor. I have my ipad and iphone thethered to the monitor via usb for charging, sync and so on. I frequently get warning messages stating that my "usb devises are drawing too much power your my computer, one or more of your usb devises has been disabled". This is just one more delightful little problem I've had since acquiring a retina display macbook and/or updating to 10.8.4......i could write a book! Anybody else experiencing this issue?

    I don't have an answer for you. What you say sound right but is the TB display really supplying power to the USB ports on it or are they being powered from the notebook? I don't know as I don't have either a TB display or a retina MBP.
    About the only thing to do is take it all into a apple store and let them figure it out. That is why they are there. To deal with the inconsistencies and problems with Apple devices.
    Best of luck to you.

Maybe you are looking for