2

I tried to run the Hugo server command as I always do. But it gave me this error.

port 1313 already in use, attempting to use an available port
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x1654d87]

I checked if the ports usage using netstat -ntlp and found nothing in the list.

I faced this issue earlier and at that time, I just uninstalled hugo using snap package manager and then reinstalled back again. And it worked that time. Now it doesnt.

What am I missing here. Note: Restarting the laptop also doesnt help.

Prabhakar Shanmugam
  • 5,634
  • 6
  • 25
  • 36

2 Answers2

5

I recommend that you run hugo server on a dynamic, private, or ephemeral port (49152 to 65535) by using the -p or --portal flag, for example:

hugo server -p 51000

I now do this always because I've also experienced weirdness with port 1313. I wrote about this on Debugging Your Hugo Website.

For info about port numbers, see https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

n m
  • 1,601
  • 6
  • 8
  • No change, Hugo server show the same message doesn't matter what port you try. Seems to be another kind of hidden error, returning the wrong message. Is an ugly bug. – Renascienza Sep 04 '21 at 11:30
2

Today I just learned that this can happen on Windows when Hyper-V is running. Hyper-V will reserve ranges of ports, and sometimes it will reserve a range that overlaps port 1313.

You can see reserved port ranges by running netsh int ip show excludedportrange protocol=tcp:

netsh int ipv4 show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
      1074        1173
      1174        1273
      1274        1373
      1557        1656
      1657        1756
      1757        1856
      1857        1956
      5357        5357
     17420       17519
     17559       17658
     50000       50059     *
     53100       53100
     53106       53106

* - Administered port exclusions.

To resolve this, you need to reserve your own range of ports. The last three steps in this stackoverflow answer worked quite well for me. Just run the dism commands in an administrator command shell.

Doug Cuthbertson
  • 463
  • 1
  • 5
  • 10