[go: nahoru, domu]

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

Realtime Database connection is flakey on desktop #106

Closed
mirzasohailbaig opened this issue Aug 25, 2017 · 107 comments
Closed

Realtime Database connection is flakey on desktop #106

mirzasohailbaig opened this issue Aug 25, 2017 · 107 comments

Comments

@mirzasohailbaig
Copy link

I'm using unity 5.5.0f3 with Firebase version 4.1.0 and whenever I try to run the Main scene for realtime database using my URL in the app.SetEditorDatabaseUrl("XXX"); it fails I made sure to set these rules
{ "rules": { ".read": "auth == null", ".write": "auth == null" } }

Another note is this use to work fine before with an older version of the Firebase SDK but now both the new Firebase SDK and the old Firebase SDK version now give me this error when running in editor. I have a feeling there is something blocking it from connecting to my Firebase but i'm not sure what it is.

`8/25/2017 7:31:29 AM [Error] WebSocket: ws_0 - could not connect
System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network.

  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0 
  at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object)
Firebase.FirebaseHandler:LogMessage(LogLevel, String)
Firebase.Unity.UnityLoggingService:LogMessage(LogLevel, String)
Firebase.Database.Internal.Logging.DefaultLogger:Error(String, String)
Firebase.Database.Internal.Logging.DefaultLogger:OnLogMessage(Level, String, String, Int64)
Firebase.Database.Internal.Logging.LogWrapper:Error(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:LogError(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:CreateSocket()
Firebase.Database.Internal.TubeSock.WebSocket:RunReader()
Firebase.Database.Internal.TubeSock.Runnable101:Run()
Google.Sharpen.Thread:InternalRun()
`

`1/2/0001 5:46:04 PM [Error] WebSocket: ws_19 - WebSocketException during handshake
Firebase.Database.Internal.TubeSock.WebSocketException: unknown host: XXX ---> System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network.

  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0 
  at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in <filename unknown>:0 
  at Firebase.Database.Internal.TubeSock.WebSocket.RunReader () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object)
Firebase.FirebaseHandler:LogMessage(LogLevel, String)
Firebase.Unity.UnityLoggingService:LogMessage(LogLevel, String)
Firebase.Database.Internal.Logging.DefaultLogger:Error(String, String)
Firebase.Database.Internal.Logging.DefaultLogger:OnLogMessage(Level, String, String, Int64)
Firebase.Database.Internal.Logging.LogWrapper:Error(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:LogError(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:RunReader()
Firebase.Database.Internal.TubeSock.Runnable101:Run()
Google.Sharpen.Thread:InternalRun()
`
@a-maurice
Copy link
Contributor

Hi,

I can't seem to reproduce the problem you are seeing, but one thing stands out to me in the rules you provided.
{ "rules": { ".read": "auth == null", ".write": "auth == null" } }
means that in order to read and write to the database you need to not be authenticated at all, which seems odd to me.
If you want to not require authentication, you can use { ".read": true, ".write": true }
If you do want to require authentication, you can use { ".read": "auth != null"... }

If that doesn't help, if I'm reading this correctly the problem is happening in the Firebase editor, and not in a build, correct? And also, what system are you running this on (Windows/Mac/Linux)? That might help us track down what you are seeing.

@mirzasohailbaig
Copy link
Author
mirzasohailbaig commented Aug 26, 2017

I tried changing the rules to '{ ".read": true, ".write": true }' which is what i had before but it didn't help. My operating system is Windows and I'm just testing this in the unity editor and looking in the Firebase console to see the new data, and the errors occur in the unity editor console.

@a-maurice
Copy link
Contributor

Hmm, I'll keep looking on my end to see if I can find any problems.

And just to cover all cases, you are running this with an internet connection? Disabling my connection has been the only way I've been able to reproduce it yet, and a socket exception usually indicates a networking problem.

@mirzasohailbaig
Copy link
Author

Yes I'm connected to the internet I even tried building to android device to see if it could be a unity editor issue, but that didn't help either.

@a-maurice
Copy link
Contributor

Our best guess is that is has something to do with an internet connection problem, possibly a firewall that is blocking it?

One suggestion is to turn on more log debugging, as we print out through out the connection process. To do so, you can add:

  FirebaseApp.LogLevel = LogLevel.Verbose;
  FirebaseDatabase.DefaultInstance.LogLevel = LogLevel.Verbose;  // Or your database instance, if not using the default.

That should print out what ip address it's trying to use, the socket, etc. which might have some explanation of the problem.

Another thing to try would be connecting directly with the REST api, as that will confirm that you are able to connect to your project at all.

@mirzasohailbaig
Copy link
Author

I tried connecting to my phone's hotspot instead and everything works fine on it, so its simply my router that I think someone may have reset and is now blocking connection to Firebase, which explains why it stopped working. However I still can't figure out what settings I can try to get my router to work with Firebase as well, simply turning off firewall did not work. Any advice based on the settings I can mess with be helpful.

options_1
options_2

Editor Console log for details
log

Just for details I have Spectrum as my internet provider and I'm using the default router/modem they provided Ubee (model: DDW36C).

@mirzasohailbaig
Copy link
Author

Never mind it just took time for my settings to start working on the router and now everything appears to be working fine. Also I believe the three settings I enabled that made Firebase connections possible again were [Multicast Enable, DNS Relay, and UPnP Enable].

Thanks a-maurice your help was much appreciated.

@PathToLife
Copy link
PathToLife commented Nov 24, 2017

I can confirm that this issue is tied into network problems related with routers..

But this is happening way too much to be ignored. Of a team of 10 devs, 5 of them have experienced this problem on public and private networks that otherwise work fine for everything else!

Can we please repoen and try diagnose if there is a way to workaround this?
I feel a roll back to a previous version of firebase and installing .net 3.5 in unity will help mitigate these issues.

11/24/2017 5:05:19 AM [Error] WebSocket: ws_3 - WebSocketException during handshake
Firebase.Database.Internal.TubeSock.WebSocketException: unknown host: super-awesome-massiveproject.firebaseio.com ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0 
  at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in <filename unknown>:0 
  at Firebase.Database.Internal.TubeSock.WebSocket.RunReader () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object)
Firebase.FirebaseHandler:LogMessage(LogLevel, String)
Firebase.Unity.UnityLoggingService:LogMessage(LogLevel, String)
Firebase.Database.Internal.Logging.DefaultLogger:Error(String, String)
Firebase.Database.Internal.Logging.DefaultLogger:OnLogMessage(Level, String, String, Int64)
Firebase.Database.Internal.Logging.LogWrapper:Error(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:LogError(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:RunReader()
Firebase.Database.Internal.TubeSock.Runnable101:Run()
Google.Sharpen.Thread:InternalRun()

@mirzasohailbaig
Copy link
Author

As requested I'm reopening the issue, since it seems like something that Firebase should actually resolve.

@stewartmiles
Copy link
Contributor

@PathToLife is there anything you can share about your reproduction environment?

Also, any chance you could try out the iOS or Android samples
https://github.com/firebase/quickstart-ios/tree/master/database
https://github.com/firebase/quickstart-android/tree/master/database
in the same environment?

Since we have different network stacks between each environment it would be interesting to see whether the problem lies in there.

TBH The connection to the database is simply using WebSocket, I would assume that in an environment where RT DB connections are failing you would see other connections fail.

@dbarla
Copy link
dbarla commented Dec 6, 2017

Hello, im having the same issue. All was working fine and suddenly this started to appear. Internet is fine. Router is like always and Rules are like always.

@dbarla
Copy link
dbarla commented Dec 6, 2017

1/2/0001 6:01:00 PM [Error] WebSocket: ws_17 - WebSocketException during handshake
Firebase.Database.Internal.TubeSock.WebSocketException: unknown host: XXXX.XXXX.firebaseio.com ---> System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network.

at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in :0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in :0
at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in :0
at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in :0
--- End of inner exception stack trace ---
at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in :0
at Firebase.Database.Internal.TubeSock.WebSocket.RunReader () [0x00000] in :0

@dbarla
Copy link
dbarla commented Dec 6, 2017

Im seeing this behaviour 2 times in same day after working a little with the Database. Same machine, same Router Config,....Log with Unreachable again...what to do? I need to put this in Production and im not sure what will happen. No idea how to manage this State either. Im trying to grab "e2.DatabaseError" with no luck too. It happens 1 time out of 100 interactions. But still is annoying because the App will crash except managing this e2.DatabaseError (if i manage to understand how).

@piofrey
Copy link
piofrey commented Jan 11, 2018

Same for me. Accessing realtime database is working fine in most of tested networks, including mobile hotspot, except for one private network in the office, where I constantly get the following error. It doesn't matter if I try with unity editor or from a build on iOS or Android.

01/11/2018 10:08:10 [Error] WebSocket: ws_2 - WebSocketException during handshake
Firebase.Database.Internal.TubeSock.WebSocketException: unknown host: <firebase_URL> ---> System.Net.Sockets.SocketException: Connection timed out
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0 
  at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Firebase.Database.Internal.TubeSock.WebSocket.CreateSocket () [0x00000] in <filename unknown>:0 
  at Firebase.Database.Internal.TubeSock.WebSocket.RunReader () [0x00000] in <filename unknown>:0 
UnityEngine.Debug:LogError(Object)
Firebase.Platform.FirebaseLogger:LogMessage(PlatformLogLevel, String)
Firebase.Unity.UnityLoggingService:LogMessage(PlatformLogLevel, String)
Firebase.Database.Internal.Logging.DefaultLogger:Error(String, String)
Firebase.Database.Internal.Logging.DefaultLogger:OnLogMessage(Level, String, String, Int64)
Firebase.Database.Internal.Logging.LogWrapper:Error(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:LogError(String, Exception)
Firebase.Database.Internal.TubeSock.WebSocket:RunReader()
Firebase.Database.Internal.TubeSock.Runnable101:Run()
Google.Sharpen.Thread:InternalRun()

Accessing Firebase realtime database via CURL and pure REST API is working fine in that network.
Any ideas?

@EyalBira
Copy link
EyalBira commented Jan 20, 2018

I am getting the same issue with the router. Working fine with the mobile network and with a hotspot. Any suggestions? This might happen for users as well, making this an unreliable option...

Unity 2017.30f3 / Firebase SDK 4.4.0

@TeddyMathias
Copy link

Having the same issue today as @EyalBira . Unity 2017.30f3 / Firebase SDK 4.4.0. Producing "WebSocketException during handshake" error. Works with my mobile Hotspot, not working through my Spectrum internet router.

@NeelimaNair
Copy link
NeelimaNair commented Mar 30, 2018

I have been encountering similar problem on multiple wi-fi networks from yesterday. Mobile hot spot works fine and I am able to connect to firebase. I get network error only for wifi connections which had been working fine till day before yesterday.

@Matthewek
Copy link

Any updates about this issue? Temporary disabling anti-virus on my imac helped, but that is not a solution unfortunately.

@hieupt1289
Copy link

I also have same issue with Lan network but still ok with hotspot form mobilenetwork source. Anyone have solution for that, even temporary.

@Matthewek
Copy link
Matthewek commented Apr 16, 2018

In my case it was antivirus that was blocking it (Kaspersky internet security 2017) - disabling it or, disabling "Check secure connections HTTPS" in preferences temporary fixed this issue, here is response I had from firebase tech team:

Regarding the issue, you may try using other anti virus or whitelist Firebase as our SDK doesn't work well with proxies, firewalls or anti virus, sorry for this. Here's the whitelist domain for Realtime Database:

*.firebaseio.com

Unfortunately, if your antivirus is too restrictive and chooses to block Firebase, I don't believe there's anything we can do to mitigate this at the moment.

Rest assured that we are exploring potential solutions to work this around. However, I could not guarantee anything at this time, sorry for this.

@clockworkdojo
Copy link
clockworkdojo commented Apr 27, 2018

Exact same issue.

  • Firebase 4.5.2
  • Unity 2018.2.0b2
  • macOS 10.13.4
  • Netgear Nighthawk R7000 with latest firmware.
  • Verizon Fios

...but if I just tether off an iPhone, works just fine.

@mirzasohailbaig
Copy link
Author

As it has been mentioned before this is a real issue for end users more than developers. Since developers can use a workaround to get it to work eventually, but if the end users comes across the issue they will probably not spend the time to debug it.

I'd recommend that for the time being if you must use firebase with unity, it would be in your best interest to use their rest API to connect firebase database with unity, libraries like "RestSharp" or "RestClient for Unity" make this a fairly easy process. Keep in mind even if you don't come across the issue, it is possible one of your end users will come across this issue since it is due to wireless routers and their security settings.

@clockworkdojo
Copy link
clockworkdojo commented Apr 27, 2018

Well, the workaround that I just found is:
TunnelBear ...I just turned on a VPN.
Now it works for me... hopefully it's fixed before deployment? ...but yeah, I should just avoid the package entirely, I guess.

@Matthewek
Copy link

mirzasohailbaig - would you please provide any examples how to connect to the firebase using unity and rest api ?

@clockworkdojo
Copy link

Inexplicably, it works today. I changed nothing... has anybody had a similar experience?

@mirzasohailbaig
Copy link
Author

Sorry Mattewek, I don't use firebase anymore but the details on how to make rest requests for firebase can be found here https://firebase.google.com/docs/reference/rest/database/ .

If you're using unity 2017.2 or higher I recommend using this rest client library to make it easier to write the requests. https://github.com/proyecto26/RestClient

There's one problem to this though you lose the real-time aspect of firebase by doing it this way, as far as I know.

@naskardebadri
Copy link

Just change the following under Player Settings:
Scripting Reference Version - .Net 3.5 Equivalent
Scripting Backed - Mono
Api Compatibility Level - .Net 2.0

These changes helped me overcome the issue.
Make these changes and just check if your issue gets solved.

@Squirenetic
Copy link
Squirenetic commented Mar 27, 2019

Ok, so the whole disable / enable dll instruction is a bit confusing. What I believe the op meant, and what worked for me just now (Unity 2018.3.10f21, Firebase Analytics Unity 5.6.0) was:

1: Rename the Firebase.Database.dll in /Assets/Firebase/Plugins/Mono/ to Firebase.Database.DISABLEDDLL (just to keep it around)

2: Copy Firebase.Database.dll in /Assets/Firebase/Plugins to /Assets/Firebase/Plugins/Mono/

Note: after this, Unity Complained about duplicate dlls when building to Android. To fix this:

  1. Rename Assets/Plugins/Firebase.Database.dll to Firebase.Database.DISABLEDDLL

After this, both Editor and Android (Gradle) builds work fine with the Firebase Database

Important to note: You have to do all of this in the finder/explorer. The files with file ending ".dll" in the unity project explorer ARE NOT THE REAL .dll files, but have the file ending .dll.mdb if you look in finder/explorer

Hope this can help anyone else stuck with this problem!

@KWarp
Copy link
KWarp commented Apr 1, 2019

Followed squirenetic's directions, but unfortunately it doesn't work for me.

@aslamca
Copy link
aslamca commented Apr 1, 2019

we cannot read/save data to firebase database in case if system time is wrong. Even if it is in seconds. So try to change system time -> choose internet time -> and select time.windows.com.

@MatthewPattell
Copy link

Ok, so the whole disable / enable dll instruction is a bit confusing. What I believe the op meant, and what worked for me just now (Unity 2018.3.10f21, Firebase Analytics Unity 5.6.0) was:

1: Rename the Firebase.Database.dll in /Assets/Firebase/Plugins/Mono/ to Firebase.Database.DISABLEDDLL (just to keep it around)

2: Copy Firebase.Database.dll in /Assets/Firebase/Plugins to /Assets/Firebase/Plugins/Mono/

Note: after this, Unity Complained about duplicate dlls when building to Android. To fix this:

  1. Rename Assets/Plugins/Firebase.Database.dll to Firebase.Database.DISABLEDDLL

After this, both Editor and Android (Gradle) builds work fine with the Firebase Database

Important to note: You have to do all of this in the finder/explorer. The files with file ending ".dll" in the unity project explorer ARE NOT THE REAL .dll files, but have the file ending .dll.mdb if you look in finder/explorer

Hope this can help anyone else stuck with this problem!

It works for me. Thank you!

@robertlair
Copy link

I think the key here, is that either way this is still a work around. I think everyone here is quite anxious for an actual fix from Google that will make Firebase work (the latest firebase DLL) with Unity 2018 (and now 2019). I am also quite anxious for Firestore support. This must not be that high of a priority for Google based on how long it has taken thusfar.

@MatthewPattell
Copy link

Ok, so the whole disable / enable dll instruction is a bit confusing. What I believe the op meant, and what worked for me just now (Unity 2018.3.10f21, Firebase Analytics Unity 5.6.0) was:

1: Rename the Firebase.Database.dll in /Assets/Firebase/Plugins/Mono/ to Firebase.Database.DISABLEDDLL (just to keep it around)

2: Copy Firebase.Database.dll in /Assets/Firebase/Plugins to /Assets/Firebase/Plugins/Mono/

Note: after this, Unity Complained about duplicate dlls when building to Android. To fix this:

  1. Rename Assets/Plugins/Firebase.Database.dll to Firebase.Database.DISABLEDDLL

After this, both Editor and Android (Gradle) builds work fine with the Firebase Database

Important to note: You have to do all of this in the finder/explorer. The files with file ending ".dll" in the unity project explorer ARE NOT THE REAL .dll files, but have the file ending .dll.mdb if you look in finder/explorer

Hope this can help anyone else stuck with this problem!

Found that the editor still has problems. For example:

https://stackoverflow.com/questions/55569517/unity-firebase-realtime-database-orderbychild-does-not-work

This problem is only in the editor.

@eladleb
Copy link
eladleb commented Jun 1, 2019

I tried the quickstart example again today and I'm quite disappointed to see that this hasn't been resolved.

I think the honest thing to do is to clearly write in the desktop workflow page that realtime database is not supported on the desktop Unity Editor until this is resolved.
We were under the impression this was going to be resolved last year but eventually switched to REST access to better support us during development.

I'd much rather be given an answer that clearly states, it's not a priority / it's not going to be resolved than to keep checking and getting disappointed again and again :(

@yezzerfv
Copy link
yezzerfv commented Jun 1, 2019 via email

@eladleb
Copy link
eladleb commented Jun 20, 2019

@stewartmiles are there any updates on this issue? Or is it not on the roadmap anymore?

@CristianSerranoMartinez

I comfirm is a error over network... please chek your router or firewell

@stewartmiles
Copy link
Contributor

@eladleb we're working on it, at the moment we think we have one more issue to solve before we can switch to the C++ implementation.

@ferretnt
Copy link
ferretnt commented Jul 3, 2019

SDK 6.2.0 release notes say moved to C++ SDK in editor, implying fixed. Such excitement. Downloading...

@alexames
Copy link
alexames commented Jul 3, 2019

With the update to the C++ implementation on the the desktop version of the SDK we expect that this should be fixed. If you still see issues please open a new bug so we can track and resolve the issue.

@alexames alexames closed this as completed Jul 3, 2019
@fingerfunkerNick
Copy link

Status is the same. Very sad. No way to get Firebase to function using .net 4 and Unity 2019 and macbook. Now the door is closing for using the famous .net 3.5 workaround, since 3.5 is no longer supported in Unity 2019.

@a-maurice
Copy link
Contributor

Hi @fingerfunkerNick

That's unfortunate to hear. What version of Unity are you still getting these problems on?

Can you enable verbose logging, and provide any logs concerning this, particularly around WebSockets? To enable verbose logging, you can use:

Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Verbose;

Thanks!

@fingerfunkerNick
Copy link
fingerfunkerNick commented Jul 11, 2019 via email

@KWarp
Copy link
KWarp commented Jul 11, 2019

For the record, the C++ implementation has been working great for me.

Unity 2018.3.f1
Mac OS High Sierra
.Net 4 SDK

@fingerfunkerNick
Copy link
fingerfunkerNick commented Jul 16, 2019 via email

@warren30815
Copy link

螢幕快照 2019-07-20 下午7 07 14

Solution is to tick and untick two Firebase.Database file setting file as picture

@warren30815
Copy link
warren30815 commented Jul 20, 2019

This work on Unity Editor and Android device well
I haven't tested on iOS, but I think it will also make sense
Environment:
.Net 4 SDK
Unity 2018.2f1
Mac

@eladleb
Copy link
eladleb commented Jul 21, 2019

Appears to be working for me as well! Removed the previous REST code At last!
Thanks a lot @stewartmiles 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests