full-stack-fastapi-template icon indicating copy to clipboard operation
full-stack-fastapi-template copied to clipboard

Unable to reload backend with start-reload.sh script due to '[Errno 98] Address already in use' error

Open jceyrac opened this issue 5 years ago • 13 comments

Hi everyone,

I'm developing services on the backend side and struggling to reload it in order to take into account my changes with the /start-reload.sh script:

root@f9f21e5f6088:/app# bash /start-reload.sh
Checking for script in /app/prestart.sh
Running script /app/prestart.sh
INFO:__main__:Initializing service
INFO:__main__:Starting call to '__main__.init', this is the 1st time calling it.
INFO:__main__:Service finished initializing
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO:__main__:Creating initial data
INFO:__main__:Initial data created
ERROR:    [Errno 98] Address already in use

Thinking it could be an issue with an old container not visible but still running in the background I removed all images and containers and rebuilt everything but I'm still having the issue unfortunately. Any idea of how I could solve this? Thanks a lot!!

jceyrac avatar Nov 09 '20 16:11 jceyrac

[Errno 98] Address already in use

I guess it's a port has occupied, you can use kill command to close. e.g.

kill -9 `lsof -t -i:port`

if not, ignore my answer. :)

wxy2077 avatar Nov 10 '20 03:11 wxy2077

you can also comment out alembic https://github.com/tiangolo/full-stack-fastapi-postgresql/blob/490c554e23343eec0736b06e59b2108fdd057fdc/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app/prestart.sh#L7

haviduck avatar Nov 12 '20 02:11 haviduck

Thanks for your replies @CoderCharm and @haviduck!

About the first the first solution, unfortunately it seems that lsof is not installed by default on the docker container, did you have to install it manually one the container?:

MacBook-Pro-de-Jerome:verva jeromeceyrac$ docker-compose exec backend bash
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
WARNING: The following deploy sub-keys are not supported and have been ignored: labels
root@c560f43d0b7f:/app# lsof
bash: lsof: command not found
root@c560f43d0b7f:/app# 

I'll try to install it manually...

Commenting alembic doesn't seem to solve the issue unfortunately (I've commented the line in pre_start.py and restared the backend container).

Is it a normal behaviour that the address is in use by default since because I haven't changed any of the default configuration...

jceyrac avatar Nov 13 '20 15:11 jceyrac

Ok, I've installed lsof, so I guess now I need to find out which process and port the reload pre_start.sh script is using and are occupied? The lsof command is returning quite a lot of stuff :(

root@c560f43d0b7f:/app# lsof
COMMAND PID USER   FD      TYPE             DEVICE SIZE/OFF     NODE NAME
uvicorn   1 root  cwd       DIR               0,80      608 39804987 /app
uvicorn   1 root  rtd       DIR              0,161     4096  2491045 /
uvicorn   1 root  txt       REG              0,161    36864  1183601 /usr/local/bin/python3.7
uvicorn   1 root  mem       REG              254,1           1183601 /usr/local/bin/python3.7 (path dev=0,161)
uvicorn   1 root  mem       REG              254,1            131672 /lib/x86_64-linux-gnu/liblzma.so.5.2.4 (path dev=0,161)
...

lsof_return.txt

jceyrac avatar Nov 13 '20 15:11 jceyrac

Same error here, does anyone any idea?

juanmarin96 avatar Nov 13 '20 23:11 juanmarin96

I had the same problem, to solve this you should comment line 54 in docker-compose.override.yml and uncomment line 53. It should looks like this:

    command: bash -c "while true; do sleep 1; done"
    # command: /start-reload.sh

After that everything works perfect.

EmilM32 avatar Nov 24 '20 18:11 EmilM32

Hi! I don't know if this has already been solved but as any of these methods worked for me because my "flower" service was failing since the beginning. Once I solved it, it was working great! The solution was to modify the docker-compose.yml file and mher/flower adding tag like this: mher/flower:0.9.4

Leodolz avatar Sep 05 '21 16:09 Leodolz

Hi! I don't know if this has already been solved but as any of these methods worked for me because my "flower" service was failing since the beginning. Once I solved it, it was working great! The solution was to modify the docker-compose.yml file and mher/flower adding tag like this: mher/flower:0.9.4

yeah :)

https://github.com/tiangolo/full-stack-fastapi-postgresql/issues/294#issuecomment-708839262

haviduck avatar Sep 06 '21 01:09 haviduck

Having this issue as well. Port is in use.

limsammy avatar Sep 10 '21 01:09 limsammy

I've tried everything, and yet I still have the issue, has anyone found another solution?

liam-cornu avatar Oct 21 '21 17:10 liam-cornu

Hi, it might be a very stupid question but I cannot find the "start-reload.sh" anywhere. Where is it located? or was it removed?

floschne avatar Apr 06 '22 13:04 floschne

I had the same problem, to solve this you should comment line 54 in docker-compose.override.yml and uncomment line 53. It should looks like this:

    command: bash -c "while true; do sleep 1; done"
    # command: /start-reload.sh

After that everything works perfect.

Thanks a lot. I spent hours to find out what's wrong until I find your fix. I think this project really needs some love from the maintainer (@tiangolo). I wasted many hours make it work fine (struggled with flower too)

mbnoimi avatar Jul 16 '22 08:07 mbnoimi