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

Bug: Access denied listening on port 5115 #90

Closed
JvdMaat opened this issue Jun 23, 2022 · 8 comments
Closed

Bug: Access denied listening on port 5115 #90

JvdMaat opened this issue Jun 23, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@JvdMaat
Copy link

JvdMaat commented Jun 23, 2022

I am not an Administrator on my laptop, and previously HASS.Agent worked fine, however after running the latest update (2212.0.7.0 according to the installer. 2022.12.0 in the app), I now get these errors in the log:
2022-06-22 08:31:04.939 -04:00 [INF] [MQTT] Initial registration completed
2022-06-22 08:31:05.700 -04:00 [FTL] An unexpected error occurred when attempting to start the server
System.Net.HttpListenerException (5): Access is denied.
at System.Net.HttpListener.AddPrefixCore(String registeredPrefix)
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Grapevine.RestServer.Start()
at Grapevine.MiddlewareExtensions.Run(IRestServer server)
at HASS.Agent.API.ApiManager.Initialize()
2022-06-22 08:31:05.701 -04:00 [FTL] [LOCALAPI] Error trying to bind the API to port 5115: Cannot access a disposed object.
Object name: 'System.Net.HttpListener'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListener'.
at System.Net.HttpListener.CheckDisposed()
at System.Net.HttpListener.Stop()
at Grapevine.RestServer.Start()
at Grapevine.MiddlewareExtensions.Run(IRestServer server)
at HASS.Agent.API.ApiManager.Initialize()
2022-06-22 08:53:08.616 -04:00 [INF] [SYSTEMSTATE] Session ending: system shutting down

Additionally, the firewall rule wasn't put in place during the install (to allow port 5115 inbound), but I added that manually.
On the Local API config page, I clicked the Execute Port Reservation button, and manually ran the command:
netsh http add urlacl url=http://+:5115/ user="DOMAIN\USER"
(It was ran as DOMAIN\ADMINUSER. And gave me an Error 183, Cannot create a file when that file already exists.)

I'm wondering if this is an issue due to me running HASS,Agent as non-admin, and a different user account with admin irights installing it. (I did make the mistake of initially installing in the Admin user Appdata on update, so I had to uninstall and redo the install correctly to point to my non-admin appdata.)

@LAB02-Admin LAB02-Admin self-assigned this Jun 23, 2022
@LAB02-Admin LAB02-Admin added the bug Something isn't working label Jun 23, 2022
@LAB02-Admin
Copy link
Member

That's odd, I'll look into it and let you know

@LAB02-Admin
Copy link
Member

Could you please run:

netsh http delete urlacl url=http://+:5115/

It should say: URL reservation successfully deleted

Afterwards run yours again:

netsh http add urlacl url=http://+:5115/ user="DOMAIN\USER"

Which should then say: URL reservation successfully added

And afterwards, after restarting HASS.Agent, it should work.

I'll change the reservation to allow for all users, but I have to make sure that'll work in all UI languages. Your setup (a different admin user) is actually really smart, so HASS.Agent should be able to work with that.

Created a ticket: [hassagent-105]

@JvdMaat
Copy link
Author

JvdMaat commented Jun 24, 2022

Worked like a charm.

I'm guessing this is because I accidentally installed it in the AdminUser AppData, and it added the URL reservation for the AdminUser, and then upon uninstall that did not get removed? (So there was a URL reservation for DOMAIN\ADMINUSER, which prevented me from adding it as DOMAIN\USER)

@LAB02-Admin
Copy link
Member

That's exactly right :)

I have the fix ready for the next beta - it'll now reserve the port for any user, so hopefully it won't be a problem for you anymore in the coming versions.

@nferch
Copy link

nferch commented Jun 24, 2022

I seem to be having a similar problem, I get the "Error trying to bind the API to port 5115" error and this in the log:

2022-06-24 13:48:26.264 -04:00 [FTL] One or more ports are already in use by another application.
System.ArgumentException: One or more ports are already in use by another application.
 ---> System.Net.HttpListenerException (32): The process cannot access the file because it is being used by another process.
   at System.Net.HttpListener.AddPrefixCore(String registeredPrefix)
   at System.Net.HttpListener.AddAllPrefixes()
   at System.Net.HttpListener.Start()
   at Grapevine.RestServer.Start()
   --- End of inner exception stack trace ---
   at Grapevine.RestServer.Start()
2022-06-24 13:48:26.265 -04:00 [FTL] [PROGRAM] FirstChanceException: Cannot access a disposed object.
Object name: 'System.Net.HttpListener'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListener'.
   at System.Net.HttpListener.CheckDisposed()
   at System.Net.HttpListener.Stop()
2022-06-24 13:48:26.265 -04:00 [FTL] [LOCALAPI] Error trying to bind the API to port 5115: Cannot access a disposed object.
Object name: 'System.Net.HttpListener'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListener'.
   at System.Net.HttpListener.CheckDisposed()
   at System.Net.HttpListener.Stop()
   at Grapevine.RestServer.Start()
   at Grapevine.MiddlewareExtensions.Run(IRestServer server)
   at HASS.Agent.API.ApiManager.Initialize()

I've checked via netstat and Process Explorer that nothing else is using port 5115.

It doesn't appear that the automatic port reservation is working, and even when I do it manually with netsh http add urlacl url=http://+:5115/ user=Everyone I get the same error.

@LAB02-Admin
Copy link
Member

Hey @nferch,

What Windows version are you using?

Perhaps try rebooting, then delete the rule and add it afterwards (from an elevated cmd prompt).

@nferch
Copy link

nferch commented Jun 25, 2022

@LAB02-Admin Thanks, that did the trick.

Am using Windows 10.0.19043.1766

@LAB02-Admin
Copy link
Member

Great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants