Skip to content

Bug: Access denied listening on port 5115 #90

Closed

Description

@JvdMaat

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.)

Activity

  1. self-assigned this
    on Jun 23, 2022
  2. LAB02-Admin commented on Jun 23, 2022

    @LAB02-Admin
    Member

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

  3. LAB02-Admin commented on Jun 24, 2022

    @LAB02-Admin
    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]

  4. JvdMaat commented on Jun 24, 2022

    @JvdMaat
    Author

    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)

  5. LAB02-Admin commented on Jun 24, 2022

    @LAB02-Admin
    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.

  6. nferch commented on Jun 24, 2022

    @nferch

    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.

  7. LAB02-Admin commented on Jun 24, 2022

    @LAB02-Admin
    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).

  8. nferch commented on Jun 25, 2022

    @nferch

    @LAB02-Admin Thanks, that did the trick.

    Am using Windows 10.0.19043.1766

  9. LAB02-Admin commented on Jun 26, 2022

    @LAB02-Admin
    Member

    Great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions