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

SocketException: Not enough buffer space #131

Closed
aeberts opened this issue Apr 22, 2015 · 23 comments
Closed

SocketException: Not enough buffer space #131

aeberts opened this issue Apr 22, 2015 · 23 comments
Labels
udp-repl Issued related to the legacy UDP REPL
Milestone

Comments

@aeberts
Copy link

aeberts commented Apr 22, 2015

When starting Arcadia/Unity from the unity5-repl-fix branch, I get a System.Net.SocketException: Not enough buffer space is available error.

Platform: OSX 10.10.2
Unity: 5.0.1f1
Arcadia: unity5-repl-fix branch

Repro steps:

  • Download and install Unity*** (installed on external drive - i.e. Unity not installed on boot volume)
  • Create new project from within Unity (on boot volume)
  • Quit Unity
  • Clone Arcadia repo to project Assets folder
  • Git checkout unity5-repl-fix branch with:
    git checkout -b unity5-repl-fix origin/unity5-repl-fix
  • Restart Unity -> watch the compiled files appear in Compiled folder
  • Errors appear in console:
System.Net.Sockets.SocketException: Not enough buffer space is available
  at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.set_SendBufferSize (Int32 value) [0x00000] in <filename unknown>:0 
  at arcadia/repl$start_server__26421.invokePrim (Int64 ) [0x000d7] in repl.clj:113 
  at arcadia/repl$start_server__26421.invoke (System.Object ) [0x00000] in <filename unknown>:0 
  at clojure.lang.Var.invoke (System.Object arg1) [0x00000] in <filename unknown>:0 
  at ClojureRepl.StartREPL () [0x00000] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/ClojureRepl.cs:41 
  at Arcadia.Initialization.StartREPL () [0x00000] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/Initialization.cs:58 
  at Arcadia.Initialization.Initialize () [0x00014] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/Initialization.cs:21 
  at Arcadia.Initialization..cctor () [0x00000] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/Initialization.cs:12 
UnityEditor.EditorAssemblies:SetLoadedEditorAssemblies(Assembly[])

also:

Object reference not set to an instance of an object (at arcadia/hydrate.clj:920)
UnityEngine.Debug:LogError(Object)
arcadia/compiler$import_asset__26560:invoke(Object)
arcadia/compiler$import_assets__18193:invoke(Object)
clojure.lang.Var:invoke(Object)
ClojureAssetPostprocessor:OnPostprocessAllAssets(String[], String[], String[], String[]) (at Assets/Arcadia/Editor/ClojureAssetPostprocessor.cs:9)
UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])
@nasser
Copy link
Contributor

nasser commented Apr 24, 2015

Very strange. We haven't seen that one before.

What's triggering it is the fact that we set the send/receive buffer sizes to 5Mb here. Hacking that to a smaller number might fix it for you. It is still odd that you cannot have 5Mb of UDP buffer space though...

Can you try it with the develop branch? unity5-repl-fix is merged in by now. Can you try it with a Unity install on the boot volume? That shouldn't make a difference, but its worth a shot anyway.

@aeberts
Copy link
Author

aeberts commented Apr 24, 2015

Hey Ramsey,

I tried it with both the unity5-repl-fix branches and the develop branches and had the same results. I'm quite sure that it's the line you highlighted and I tried various different values e.g. (* 1 8192) , (* 1024 10000) to see if I could get Unity to accept something. Nothing worked unfortunately.

This feels like a Mono bug to me because if I try to set the SendBufferSize to the default value explicitly (* 1024 8) Unity will crash when repl.clj is compiled and run.

I also tried running Unity as root to see if it was a socket permissions issue but that didn't work either.

I will try installing Unity on another machine I have see on the boot volume to see if that changes anything and report back.

@nasser
Copy link
Contributor

nasser commented Apr 24, 2015

Very strange. The off-boot volume installation should not make a difference, but it is the only thing that stands out, so I would definitely try and eliminate that variable.

What happens if you remove the lines altogether?

@aeberts
Copy link
Author

aeberts commented Apr 24, 2015

Removing the lines altogether results in Unity crashing. Is there are Unity log file that might give us a hint to what's happening?

@nasser
Copy link
Contributor

nasser commented Apr 24, 2015

Yes. ~/Library/Logs/Unity/Editor.log

Full list: http://docs.unity3d.com/Manual/LogFiles.html

@aeberts
Copy link
Author

aeberts commented Apr 24, 2015

Here's what ~/Library/Logs/Unity/Editor.log has to say:

... snip ...
(Filename: Assets/Arcadia/Editor/ClojureRepl.cs Line: 41)

Starting REPL...

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebug.gen.cpp Line: 56)

Receiving unhandled NULL exception
Launching bug reporter
Obtained 51 stack frames.
#0  0x000001056a2155 in mono_assembly_get_image
#1  0x000001258fddfe in StartForcingEditorApplicationUpdates
#2  0x00000134f6cf5a in  (wrapper managed-to-native) ClojureRepl:StartForcingEditorApplicationUpdates () + 0xba (0x134f6cea0 0x134f6cf89) [0x10f8ac660 - Unity Child Domain]
#3  0x00000125a72ac0 in  ClojureRepl:StartREPL () + 0x1d0 (0x125a728f0 0x125a72b02) [0x10f8ac660 - Unity Child Domain]
#4  0x00000125a728b5 in  Arcadia.Initialization:StartREPL () + 0x45 (0x125a72870 0x125a728d9) [0x10f8ac660 - Unity Child Domain]
#5  0x000001258e87f5 in  Arcadia.Initialization:Initialize () + 0xb5 (0x1258e8740 0x1258e8845) [0x10f8ac660 - Unity Child Domain]
#6  0x000001258e8705 in  Arcadia.Initialization:.cctor () + 0x45 (0x1258e86c0 0x1258e8729) [0x10f8ac660 - Unity Child Domain]
#7  0x0000010dc00b46 in  (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr) + 0xf6 (0x10dc00a50 0x10dc00c79) [0x10f8ac660 - Unity Child Domain]
#8  0x000001055e7bd4 in mono_get_runtime_build_info
#9  0x0000010570bb23 in mono_runtime_invoke
#10 0x0000010570bffe in mono_runtime_class_init_full
#11 0x0000010570bbf1 in mono_runtime_class_init
#12 0x000001056d26f9 in mono_register_jit_icall
#13 0x000001258b9d1b in  (wrapper managed-to-native) System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (intptr) + 0x8b (0x1258b9c90 0x1258b9d4a) [0x10f8ac660 - Unity Child Domain]
#14 0x000001258b9c54 in  System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (System.RuntimeTypeHandle) + 0x124 (0x1258b9b30 0x1258b9c78) [0x10f8ac660 - Unity Child Domain]
#15 0x000001258b99aa in  UnityEditor.EditorAssemblies:ProcessEditorInitializeOnLoad (System.Type) + 0x7a (0x1258b9930 0x1258b9a90) [0x10f8ac660 - Unity Child Domain]
#16 0x000001258b7a85 in  UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes () + 0x195 (0x1258b78f0 0x1258b7bb2) [0x10f8ac660 - Unity Child Domain]
#17 0x000001258b75ff in  UnityEditor.EditorAssemblies:SetLoadedEditorAssemblies (System.Reflection.Assembly[]) + 0x6f (0x1258b7590 0x1258b7623) [0x10f8ac660 - Unity Child Domain]
#18 0x000001258b773d in  (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr) + 0xfd (0x1258b7640 0x1258b7870) [0x10f8ac660 - Unity Child Domain]
#19 0x000001055e7bd4 in mono_get_runtime_build_info
#20 0x0000010570bb23 in mono_runtime_invoke
#21 0x0000010073450a in ScriptingInvocation::Invoke(MonoException**, bool)
#22 0x00000100734439 in ScriptingInvocation::Invoke()
#23 0x0000010071d01d in MonoManager::SetupLoadedEditorAssemblies()
#24 0x0000010071e619 in MonoManager::EndReloadAssembly(DomainReloadingData const&, dynamic_bitset)
#25 0x0000010071ed50 in MonoManager::ReloadAssembly(dynamic_bitset, bool)
#26 0x00000100bc5e3a in ReloadAllUsedAssemblies(bool)
#27 0x00000100bc7b79 in RecompileScripts(int, bool, BuildTargetPlatform, bool)
#28 0x00000100bcd745 in LoadMonoAssembliesOrRecompile()
#29 0x00000101004f57 in Application::InitializeProject()
#30 0x000001011e2e31 in -[EditorApplication applicationDidFinishLaunching:]
#31 0x007fff90f39cdc in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
#32 0x007fff90e2b244 in _CFXNotificationPost
#33 0x007fff96cfac31 in -[NSNotificationCenter postNotificationName:object:userInfo:]
#34 0x007fff9136d9ab in -[NSApplication _postDidFinishNotification]
#35 0x007fff9136d716 in -[NSApplication _sendFinishLaunchingNotification]
#36 0x007fff9136a536 in -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:]
#37 0x007fff91369f75 in -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:]
#38 0x007fff96d1a1e8 in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:]
#39 0x007fff96d1a059 in _NSAppleEventManagerGenericHandler
#40 0x007fff8cd2099c in aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned int, unsigned char*)
#41 0x007fff8cd20719 in dispatchEventAndSendReply(AEDesc const*, AEDesc*)
#42 0x007fff8cd20623 in aeProcessAppleEvent
#43 0x007fff89129a2e in AEProcessAppleEvent
#44 0x007fff91366626 in _DPSNextEvent
#45 0x007fff91365730 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#46 0x007fff91359593 in -[NSApplication run]
#47 0x007fff91344a14 in NSApplicationMain
#48 0x000001011f953e in EditorMain(int, char const**)
#49 0x000001011f9c99 in main
#50 0x00000100002484 in start
Symbol file LoadedFromMemory doesn't match image /Volumes/Slick/Applications/Unity/Unity.app/Contents/PlaybackEngines/WebGLSupport/UnityEditor.WebGL.Extensions.dll
Symbol file /Volumes/Slick/Applications/Unity/Unity.app/Contents/PlaybackEngines/WebGLSupport/UnityEditor.WebGL.Extensions.dll.mdb doesn't match image /Volumes/Slick/Applications/Unity/Unity.app/Contents/PlaybackEngines/WebGLSupport/UnityEditor.WebGL.Extensions.dll
Launching external process: /Volumes/Slick/Applications/Unity/Unity.app/Contents/BugReporter/Unity Bug Reporter.app/Contents/MacOS/unity.bugreporter.exe
QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton)

@nasser
Copy link
Contributor

nasser commented Apr 24, 2015

Try this:

  • Quit Unity
  • Delete the Assets/Arcadia/Plugins folder
  • Delete the Library folder
  • Comment out this line
  • Start Unity

@aeberts
Copy link
Author

aeberts commented Apr 24, 2015

It works! The ClojureREPL window now shows: REPL is listening on 0.0.0.0:11211
I'm assuming that this breaks the fix implemented for unity5-repl-fix - is that right?

Now I'm seeing another error in the console:

InvalidOperationException: nth not supported on this type: PersistentHashMap
clojure.lang.RT.NthFrom (System.Object coll, Int32 n, System.Object notFound)
clojure.lang.RT.nth (System.Object coll, Int32 n, System.Object notFound)
arcadia/compiler$first_form_is_ns_QMARK___18159.invoke (System.Object )
arcadia/compiler$import_asset__18183.invoke (System.Object )
arcadia/compiler$import_assets__18193.invoke (System.Object )
clojure.lang.Var.invoke (System.Object arg1)
ClojureAssetPostprocessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/Arcadia/Editor/ClojureAssetPostprocessor.cs:9)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:26)

@aeberts
Copy link
Author

aeberts commented Apr 24, 2015

After some poking around this fix produced other errors. To summarize where we are:

  • Plugins folder deleted
  • StartForcingEditorApplicationUpdates() commented out on this line
  • SendBufferSize and ReceiveBufferSize commented out near this line

Result is ->

  • Unity loads and starts the Repl
  • InvalidOperationException: nth not supported on this type error appears in console.
  • Starting the repl from a terminal gives a Message too long error:
Editor git:(develop) ✗ ruby repl-client.rb
System.Net.Sockets.SocketException: Message too long
  at System.Net.Sockets.Socket.SendTo_nochecks (System.Byte[] buffer, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint remote_end) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.SendTo (System.Byte[] buffer, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint remote_end) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.UdpClient.DoSend (System.Byte[] dgram, Int32 bytes, System.Net.IPEndPoint endPoint) [0x00000] in <filename unknown>:0 
user=> 

@nasser
Copy link
Contributor

nasser commented Apr 24, 2015

Yes, this breaks the unity5-repl-fix patch, which I was never happy/done with. What will happen is now Unity will not run your REPL commands unless the Unity app has focus (which is new in Unity 5, and broken as shit). Our StartForcingEditorApplicationUpdates fix introduces a native C plugin that forces the REPL to update independently of Unity's tomfoolery, but it hasn't been thoroughly tested beyond 'works for me' and I was afraid of issues like this.

nth not supported is harmless and we're cleaning that up. Try uncommenting the buffer size code in repl.clj and see if that gets rid of the Message too long error.

@aeberts
Copy link
Author

aeberts commented Apr 24, 2015

Uncommenting the buffer size code in repl.clj results in the same Not enough buffer space is available socket error :-/

System.Net.Sockets.SocketException: Not enough buffer space is available
  at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.set_SendBufferSize (Int32 value) [0x00000] in <filename unknown>:0 
  at arcadia/repl$start_server__22128.invokePrim (Int64 ) [0x000d7] in repl.clj:113 
  at arcadia/repl$start_server__22128.invoke (System.Object ) [0x00000] in <filename unknown>:0 
  at clojure.lang.Var.invoke (System.Object arg1) [0x00000] in <filename unknown>:0 
  at ClojureRepl.StartREPL () [0x00000] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/ClojureRepl.cs:41 
  at Arcadia.Initialization.StartREPL () [0x00000] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/Initialization.cs:58 
  at Arcadia.Initialization.Initialize () [0x00014] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/Initialization.cs:21 
  at Arcadia.Initialization..cctor () [0x00000] in /Users/zand/Documents/UnityProjects/test/Assets/Arcadia/Editor/Initialization.cs:12 
UnityEditor.EditorAssemblies:SetLoadedEditorAssemblies(Assembly[])

FWIW - if the error is indeed in Mono's socket code a user named fholm on the unity3d forums recommended a .net udp library called Lidgren which may be more stable. Here's a link to that thread .

HTH - let me know if you want to do some more testing on my config.

@nasser
Copy link
Contributor

nasser commented Apr 24, 2015

Bah! That's terrible! We will look into swapping out our networking code then.

Thank you so much for your work on this. I'm sorry there isn't an easy fix at hand, although installing Unity on the boot volume might do it if that's an option.

@aeberts
Copy link
Author

aeberts commented Apr 24, 2015

I wish I was a .net hacker and could give you a more help on this one...

Great work on Arcadia BTW - super cool stuff and the promise of working with clojure + CES = awesome! :-D

A.

@nasser
Copy link
Contributor

nasser commented Apr 24, 2015

Thanks! It means a lot that you'd say that and take time to work through this bug!

@aeberts
Copy link
Author

aeberts commented Apr 25, 2015

Did some more digging and here's another update on this one:

I had a machine running MacOS X 10.9.5 and ran Unity 5.0.1f1 with the develop branch and Arcadia started with no problems (I didn't need to comment any lines or change anything from the stock develop branch). So it appears that this bug (and it's related issues identified above) is due to some type of incompatibility with Yosemite. Let me know if you want more info...

@nasser
Copy link
Contributor

nasser commented Apr 25, 2015

Oh that's grim. Thanks for the update. We will look into it. I think @timsgardner is on 10.10, but I am not. Not sure what version he's on though.

@aeberts
Copy link
Author

aeberts commented May 13, 2015

Hey Ramsey,
Could you ping @timsgardner to see what version of OSX he's running? I sent him a quick email but didn't hear back. If he's on 10.10 (Yosemite) and Unity 5 and Arcadia is working for him then this is likely a configuration issue and probably not a Mono / Unity bug. If it turns out to be a config issue, I'll continue digging...
thanks,
Alex

@owengalenjones
Copy link

I am also seeing this error, I'm on OSX Yosemite as well. I can provide any further details if needed!

@nasser nasser added this to the Alpha 0.1 milestone Aug 23, 2016
@zcaudate
Copy link

zcaudate commented Nov 26, 2016

is there any progress with this? I've upgraded to Sierra and am getting this

System.Net.Sockets.SocketException: Not enough buffer space is available
  at System.Net.Sockets.Socket.SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.Socket.set_SendBufferSize (Int32 value) [0x00000] in <filename unknown>:0 
  at arcadia/repl$start_server__41246.invokePrim (Int64 ) [0x00000] in <filename unknown>:0 
  at arcadia/repl$start_server__41246.invoke (System.Object ) [0x00000] in <filename unknown>:0 
  at clojure.lang.Var.invoke (System.Object arg1) [0x00000] in <filename unknown>:0 
  at Arcadia.Repl.StartREPL () [0x00000] in /Users/chris/Development/tahto/anubis/Assets/Arcadia/Editor/Repl.cs:52 
  at Arcadia.Initialization.StartREPL () [0x00000] in /Users/chris/Development/tahto/anubis/Assets/Arcadia/Editor/Initialization.cs:150 
  at Arcadia.Initialization.Initialize () [0x0002d] in /Users/chris/Development/tahto/anubis/Assets/Arcadia/Editor/Initialization.cs:70 
  at Arcadia.Initialization..cctor () [0x00000] in /Users/chris/Development/tahto/anubis/Assets/Arcadia/Editor/Initialization.cs:15 
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes()

@nasser nasser removed this from the Alpha 0.1 milestone Dec 10, 2017
@green-coder
Copy link
Contributor

I have the same problem.

I am using Unity version 2017.2.2f1 as recommended in the Wiki and Arcadia's develop branch (18946fd) on MacOS High Sierra version 10.13.4.

screen shot 2018-04-28 at 5 46 25 pm

@green-coder
Copy link
Contributor

As a quick workaround, changing those lines in Arcadia/Source/arcadia/repl.clj works for me:

(set! (.. socket Client SendBufferSize) (* 1024 5000)) ;; 5Mb
(set! (.. socket Client ReceiveBufferSize) (* 1024 5000)) ;; 5Mb

into something smaller like

(set! (.. socket Client SendBufferSize) (* 1024 500)) ;; 500kb
(set! (.. socket Client ReceiveBufferSize) (* 1024 500)) ;; 500kb

@saikyun
Copy link
Contributor

saikyun commented May 13, 2018

I have the same problem using OSX Sierra.
The workaround green-coder posted worked for me as well. :)

@nasser nasser added the udp-repl Issued related to the legacy UDP REPL label May 31, 2018
@nasser nasser added this to the Beta Release milestone Oct 1, 2018
@nasser
Copy link
Contributor

nasser commented Nov 26, 2018

This is an issue with the legacy UDP REPL which has been removed from the beta branch and replaced with the Socket REPL and nREPL. Neither of them exhibit this behavior.

@nasser nasser closed this as completed Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
udp-repl Issued related to the legacy UDP REPL
Projects
None yet
Development

No branches or pull requests

6 participants