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

Unity.iOS SSL doesn't work #523

Closed
z000z opened this issue Nov 2, 2015 · 25 comments
Closed

Unity.iOS SSL doesn't work #523

z000z opened this issue Nov 2, 2015 · 25 comments
Assignees

Comments

@z000z
Copy link

z000z commented Nov 2, 2015

I tried switching my sync gateway over to SSL but it looks like that doesn't work for the iOS builds. It didn't work for any builds at first for me but I merged the recent commit into my local version:
d101ce3

And that seems to have fixed at least the OSX in editor SSL issues. I believe the problem is that Unity's version of HttpWebRequest while using the .net 2.0 (non subset) just doesn't function with SSL on iOS. If this is the correct observation, the only thing I can think of to get around this would be either to make couchbase lite .net usable with the .net 2.0 subset (seems this is probably unlikely since this looks to be a pretty large change), or possibly to move the HttpWebRequest usages behind an interface and replace that with possibly a Unity.WWW class usage.

@borrrden
Copy link
Member

borrrden commented Nov 3, 2015

@z000z I'd be willing to bet this is related to issue #481

@z000z
Copy link
Author

z000z commented Nov 3, 2015

Oh that would be cool if so, I'll re-check things once the patch comes out.

@borrrden
Copy link
Member

borrrden commented Nov 3, 2015

I will also do so, but if it still doesn't work then I will probably have to go back and file another Unity bug...><

@borrrden borrrden self-assigned this Nov 3, 2015
@zgramana zgramana added this to the Unity GA milestone Nov 7, 2015
@z000z
Copy link
Author

z000z commented Nov 9, 2015

Well I tried it out with Unity's 5.2.2.p3 version, and it still is broken. I decided to do a little more investigation and discovered that with the d101ce3 commit, it's actually not just SSL it's regular http as well that doesn't work in iOS. I decided to roll back and double check that to see if the 5.2.2p3 version fixed the SSL issue before that commit, but looks like SSL doesn't work there either (although this is for all the platforms I tried not just iOS) non-ssl though seems to work fine in all the platforms.

I was curious what exactly the thing was that was fixing the SSL for the other Unity platforms and discovered it's really just the commits in the Rackspace sub repo that are fixing the SSL in the other platforms (and also breaking all communication with iOS).

So at this commit of the subrepo, http works for all platforms I tried (osx, android, ios), SSL though for none.
couchbasedeps/dotnet-httpclient35@ca1e074

At this commit, http/SSL works for (android, osx) but on iOS neither SSL or HTTP works.
couchbasedeps/dotnet-httpclient35@b16cb46

@borrrden
Copy link
Member

borrrden commented Nov 9, 2015

I am aware of this issue, but thanks a lot for your investigation! At least you have given me comfort that it works on non-iOS platforms. As for iOS, I am not quite sure what is going on yet but I have a hunch at the moment. You are not the only user to be affected by this issue so until it is fixed I have a feeling I am going to be focusing on this.

@borrrden
Copy link
Member

@z000z I've been able to fix this issue locally, so give the issue/523 branch a shot and see if it works for you.

@z000z
Copy link
Author

z000z commented Nov 11, 2015

I checked it out, it looks like it's communicating with or without SSL, but there seems to be a new problem. For some reason it only pulled one of the documents down from the gateway instead of all of them it should have in iOS, other platforms seemed fine.

I did some experimentation and it seems to pickup any new documents I create while the app is running, but any I create while the app is not running it doesn't pick up when the app runs the next time.

@z000z
Copy link
Author

z000z commented Nov 11, 2015

I think it may have to do somehow with me using the session cookies for the replicators, noticed that I was getting these exceptions stacks after a bit:

: GOT A RESPONSE IN SendAsyncWorker
ChangeTracker: Exception in change tracker
    System.Net.WebException: The operation has timed out.
      at System.Net.CookieCollection.SearchCookie (System.Net.Cookie cookie) [0x00000] in <filename unknown>:0 
      at System.Net.WebConnectionStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0 
      at System.IO.StreamReader.ReadBuffer () [0x00000] in <filename unknown>:0 
      at System.IO.StreamReader.Read (System.Char[] buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0 
      at Newtonsoft.Json.JsonTextReader.ReadData (Boolean append, Int32 charsRequired) [0x00000] in <filename unknown>:0 
      at Newtonsoft.Json.JsonTextReader.ReadData (Boolean append) [0x00000] in <filename unknown>:0 
      at Newtonsoft.Json.JsonTextReader.ParseValue () [0x00000] in <filename unknown>:0 
      at Newtonsoft.Json.JsonTextReader.ReadInternal () [0x00000] in <filename unknown>:0 
      at Newtonsoft.Json.JsonTextReader.Read () [0x00000] in <filename unknown>:0 
      at Couchbase.Lite.NewtonsoftJsonSerializer.Read () [0x00000] in <filename unknown>:0 
      at Couchbase.Lite.Replicator.ChangeTracker.ReceivedPollResponse (IJsonSerializer jsonReader, Boolean& timedOut) [0x00000] in <filename unknown>:0 
      at Couchbase.Lite.Replicator.ChangeTracker.ChangeFeedResponseHandler (System.Threading.Tasks.Task`1 responseTask) [0x00000] in <filename unknown>:0 
      at System.Action`1[T].Invoke (.T obj) [0x00000] in <filename unknown>:0 
      at System.Threading.Tasks.TaskActionInvoker+ActionTaskInvoke`1[TResult].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0 
      at System.Threading.Tasks.Task.InnerInvoke () [0x00000] in <filename unknown>:0 
      at System.Threading.Tasks.Task.ThreadStart () [0x00000] in <filename unknown>:0 
      at System.Threading.Tasks.Task.Execute () [0x00000] in <filename unknown>:0 
      at System.Threading.Tasks.TaskScheduler.TryExecuteTask (System.Threading.Tasks.Task task) [0x00000] in <filename unknown>:0 
      at Couchbase.Lite.Util.SingleTaskThreadpoolScheduler.<QueueTask>m__0 (System.Object t) [0x00000] in <filename unknown>:0 
      at System.Threading.ParameterizedThreadStart.Invoke (System.Object obj) [0x00000] in <filename unknown>:0 
ChangeTracker: Making request to https://10.0.1.25:4984/sync_gateway/_changes

@borrrden
Copy link
Member

I've seen stuff related to that without using cookies before so I don't think the cookies are necessarily related. The problem is that Unity iOS is choking horribly on Task related stuff. There is also a bug in Sync Gateway at the moment relating to changes, I'll ask if that has any relation.

@borrrden
Copy link
Member

Alright, I changed things up a bit to be as non-blocking as possible and after implementing your PRs for issue 506 I was able to replicate with an endpoint using cookies. Let me know how things go this time around in issue/523

@z000z
Copy link
Author

z000z commented Nov 12, 2015

Cool, that looks like that fixed that previous exception but it looks like I'm still getting some odd behavior and a new exception now. These steps seem to cause it for me:

  1. Start App
  2. Create document on the sync gateway, watch document come to the app
  3. Stop App, delete app from device (so that local database is now gone)
  4. Run & Reinstall App - Document from step 2 doesn't show up.

Wait a bit and this error eventually shows up

BulkDownloader
    Response task timed out: System.Threading.Tasks.Task`1[System.Net.Http.HttpResponseMessage], System.Threading.Tasks.TpScheduler, Couchbase.Lite.Replicator.BulkDownloader[/sync_gateway/_bulk_get]
BulkDownloader: Unhandled Exception
    [HttpResponseException: StatusCode = RequestTimeout]

@borrrden
Copy link
Member

That's the exact procedure I use for test, pretty much. I have a pre-created Sync Gateway bucket that I download fresh and I am not seeing those issues at the moment. I'll keep trying to see if I get them.

@z000z
Copy link
Author

z000z commented Nov 12, 2015

I'll see if I can make reproduction case from the sample unity project in the repo as well.

@z000z
Copy link
Author

z000z commented Nov 14, 2015

Well I figured out that for some reason my dlls I'm creating aren't the same as the ones in the sample UnityDemo project, if I use the dlls in there it seems to fix my problem.

I've got a reproduction Unity project now that demonstrates the problem, although it looks like if I can figure out how to build the dlls in the same way you are it'll fix it. All I'm doing is using Xamarin Studio 5.9.8 and building the Couchbase.Lite.Unity.cbproj and then grabbing the dlls from the bin/Debug/Assets/Plugins

For some reason some of my dlls binary match the ones in that UnityDemo, but these are all binary different:
Couchbase.Lite.dll
Newtonsoft.Json.dll
System.Net.Http.Net35.dll
System.Threading.Tasks.Net35.dll

It seems the one in particular that's causing the problem for me is the System.Threading.Tasks.Net35.dll, if I replace my generated one with the one from the UnityDemo/Plugins folder the problem goes away.

@borrrden
Copy link
Member

Sounds like you forgot to update the hit sub modules.

@z000z
Copy link
Author

z000z commented Nov 14, 2015

That's what I thought too, but as far as I can tell it's all matching up here's the commits I'm using:

System.Threading.Tasks.Net35: 35c006b
Rackspace.Threading: 777017b
Rackspace: 40c56ff
SQLitePCL: d636786 [there are newer commits in this one, but this seems to be the one that matches the branch]
Stateless: 8f4bbac
Json.Net: 411d597

Does that look right to you? If so I wonder if there's maybe some sort of difference in my build environment causing something weird, like xamarin studio vs visual studio, or some sort of mono sdk problem?

@borrrden
Copy link
Member

I'll check when I get back. I'm on a crowded train ATM

@borrrden
Copy link
Member

Well those are all the correct commits. I tried rebuilding and sure enough the binaries differed for me too, so the next order of business is for me to figure out how in the world I created the good ones. I tried going back a commit or two but so far no luck...very strange. I wonder what else could have changed.

@borrrden
Copy link
Member

I found the source of the discrepancy. JSON.NET was still referencing the non-Unity TPL backport which uses async / await (which fails on Unity iOS). I guess it was a crap shoot as to which one got copied to the output. I've corrected the reference and while doing that I also eliminated the Rackspace.Threading namespace all together. At a later point I will restructure the submodules and this will eliminate one layer.

@z000z
Copy link
Author

z000z commented Nov 14, 2015

Ah that makes sense, will be nice to have the stack a little simpler.

@z000z
Copy link
Author

z000z commented Nov 16, 2015

When I was trying to compile the changes I ran into one issue, the System.Net.Http.Unity.csproj was changed to reference:

    <ProjectReference Include="..\System.Threading.Tasks\System.Threading.Tasks.Unity.csproj">

But I don't have that path, I had to change it to this:

    <ProjectReference Include="..\Rackspace.Threading\System.Threading.Tasks.Net35\System.Threading.Tasks.Unity.csproj">

I double checked by re-cloning the repository, possibly the System.Threading.Tasks folder didn't make it into the repo?

I just saw you made a similar change to the Couchbase.Lite.Unity.sln, thought I'd mention that one I found as well.

@borrrden
Copy link
Member

Sorry about that, it was something I forgot to back out. I backed it out
about an hour ago. I'll double check the others as well.

On Mon, Nov 16, 2015 at 10:55 AM, z000z [email protected] wrote:

When I was trying to compile the changes I ran into one issue, the
System.Net.Http.Unity.csproj was changed to reference:

<ProjectReference Include="..\System.Threading.Tasks\System.Threading.Tasks.Unity.csproj">

But I don't have that path, I had to change it to this:

<ProjectReference Include="..\Rackspace.Threading\System.Threading.Tasks.Net35\System.Threading.Tasks.Unity.csproj">

I double checked by re-cloning the repository, possibly the
System.Threading.Tasks folder didn't make it into the repo?

I just saw you made a similar change to the Couchbase.Lite.Unity.sln,
thought I'd mention that one I found as well.


Reply to this email directly or view it on GitHub
#523 (comment)
.

@z000z
Copy link
Author

z000z commented Nov 16, 2015

Oh ok cool no problem

@borrrden
Copy link
Member

I've forgotten the status of this. We have another user with a similar problem and theirs is not resolved yet, but have the changes here resolved yours?

@z000z
Copy link
Author

z000z commented Nov 30, 2015

Yup it's all resolved for me.

borrrden added a commit that referenced this issue Dec 1, 2015
@borrrden borrrden closed this as completed Dec 1, 2015
borrrden added a commit that referenced this issue Dec 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants