[MonoTouch] Odd sporatic error on WAV uploads via PUT HTTP request.

Rolf Bjarne Kvinge rolf at xamarin.com
Tue Dec 20 03:27:50 EST 2011


On Tue, Dec 20, 2011 at 2:07 AM, Jeff Lindborg <jlindborg2000 at gmail.com>wrote:

> Couple notes I can provide after testing...

1. Can't do HTTP, server wont allow it and I don't control that side
> of it - I suppose I could spin up my own REST service to test that...
>

Yes, I think the best way to track down the problem is to create a smaller
test case. That way it's easier for other people (us) to try it out to.

Rolf


>
> 2. It fails after you start to upload - smaller files don't fail often
> (smaller meaning about 2 seconds of linear PCM recording - think of a
> voice name for an IVR system here).  But if you try enough times it'll
> eventually fail.  Large files (think 30 seconds of linear PCM
> recording) fail nearly all the time - retries will eventually go
> through but I've seen it take as many as 20 (!!!!) tries.  Clearly not
> ideal.
>
> I'm using this same class library on Windows forms apps - I've
> uploaded 3 to 5 minute recordings (yeah... people record 5 minute
> greetings for their IVR setups - evil but there it is) and they go
> through ok to the same servers on the same network (my home) so I'm
> not imagining a network problem popping in here.
>
> I changed the upload process to "chunk" the stream into 10,000 byte
> pieces just to see if it would behave differently - it didn't but I
> could see the chunks flying by before it failed so I know it's
> starting the process.
>
> Dunno how to narrow it down any further - if there's some sort of diag
> output I can gather for you guys, let me know.  The WAV file handling
> for this app is kind of it's main deal so I'm keen to smooth the edges
> on this.
>
> thanks
>
>
> On Mon, Dec 19, 2011 at 4:23 PM, Rolf Bjarne Kvinge <rolf at xamarin.com>
> wrote:
> > Hi,
> >
> > I don't know exactly what's going on, but I have a few questions that
> might
> > help you:
> >
> > * It seems you're using https, do you have the same problem with just
> http?
> > * Does it fail instantly when it fails, or does it start uploading and
> then
> > fail after some random amount of time?
> > * (If it doesn't fail instantly) does a slow network make it fail
> > faster/more often?
> > * You say you're uploading "very large wav files", but exactly how large
> is
> > "very large"?
> >
> > I don't think it's an iOS restriction you're running into if it works
> > sometimes. To me it sounds either like a network hiccup, or an obscure
> bug
> > inside MonoTouch (and the questions above will help point the location,
> but
> > in any case a reproducible test case would likely be required to track
> down
> > a MonoTouch bug).
> >
> > Rolf
> >
> > On Sun, Dec 18, 2011 at 4:23 AM, jlindborg <jlindborg2000 at gmail.com>
> wrote:
> >>
> >> Hey folks – been banging heads with this for several hours today – just
> >> adding a simple WAV file upload/download facility into my app to a REST
> >> based server – all the downloads work dandy regardless of size, however
> >> uploads will occasionally throw an error on me – if you retry the file a
> >> time or two when you get the failure they do go through but that makes
> me
> >> sad… I’d rather not have to resort to a retry hack to smother this.
> >>  Largely
> >> the same C# code is in use on my WinForms projects and uploads of very
> >> large
> >> wav files (long winded voice mail greetings for instance) go through ok
> to
> >> the same servers.
> >>
> >> So… I’m not sure if this is me being a bonehead about something (always
> a
> >> possibility) or if I’m not taking some iOS limitation into account or
> this
> >> is a bug somewhere in Mono… anyway – here’s the upload code (simplified
> a
> >> bit for brevity) .
> >> ==========
> >>
> >> private static bool UploadWavFile(string pFullResourcePath, string
> pLogin,
> >>                          string pPassword, string pLocalWavFilePath)
> >>    {
> >>        Stream oStream = null;
> >>        HttpWebRequest webReq;
> >>        byte[] buffer;
> >>        BinaryReader binReader = null;
> >>              FileStream oFileStream = null;
> >>
> >>        try
> >>        {
> >>           oFileStream = File.Open(pLocalWavFilePath, FileMode.Open);
> >>           binReader = new BinaryReader(oFileStream);
> >>           buffer = new
> byte[Convert.ToInt32(binReader.BaseStream.Length) +
> >> 1];
> >>           binReader.Read(buffer, 0, buffer.Length);
> >>        }
> >>        catch (Exception ex)
> >>        {
> >>                Console.WriteLine(ex.ToString());
> >>                return false;
> >>        }
> >>
> >>    webReq = (HttpWebRequest)WebRequest.Create(pFullResourcePath);
> >>    webReq.Method = "PUT";
> >>    webReq.ContentLength = buffer.Length;
> >>    webReq.ContentType = "audio/wav";
> >>    webReq.Credentials = new NetworkCredential(pLogin, pPassword);
> >>    webReq.KeepAlive = false;
> >>    webReq.ReadWriteTimeout= 50000;
> >>    oStream = webReq.GetRequestStream();
> >>
> >>        Try
> >>                {
> >>                            //LINE THAT THROWS ERROR FROM TIME TO TIME
> >>                            oStream.Write(buffer,0, buffer.Length);
> >>                }
> >>                catch (Exception ex)
> >>                {
> >>                  Console.WriteLine (ex.ToString());
> >>                  return false;
> >>                }
> >> ...
> >>
> >> And here’s the error it’s throwing at the noted line:
> >>
> >> System.IO.IOException: IO exception during Write. --->
> >> System.NullReferenceException: Object reference not set to an instance
> of
> >> an
> >> object\n  at Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite
> >> (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00031]
> in
> >>
> >>
> /Developer/MonoTouch/Source/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:775
> >> \n  --- End of inner exception stack trace ---\n  at
> >> Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite
> >> (Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00089]
> in
> >>
> >>
> /Developer/MonoTouch/Source/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:788
> >> \n  at Mono.Security.Protocol.Tls.SslStreamBase.BeginWrite
> (System.Byte[]
> >> buffer, Int32 offset, Int32 count, System.AsyncCallback callback,
> >> System.Object state) [0x000a3] in
> >>
> >>
> /Developer/MonoTouch/Source/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:857
> >> \n  at System.Net.WebConnection.BeginWrite (System.Net.HttpWebRequest
> >> request, System.Byte[] buffer, Int32 offset, Int32 size,
> >> System.AsyncCallback cb, System.Object state) [0x00055] in
> >>
> >>
> /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnection.cs:927
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://monotouch.2284126.n4.nabble.com/Odd-sporatic-error-on-WAV-uploads-via-PUT-HTTP-request-tp4210028p4210028.html
> >> Sent from the MonoTouch mailing list archive at Nabble.com.
> >> _______________________________________________
> >> MonoTouch mailing list
> >> MonoTouch at lists.ximian.com
> >> http://lists.ximian.com/mailman/listinfo/monotouch
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20111220/a1bea394/attachment-0001.html 


More information about the MonoTouch mailing list