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

worker_id must be less than task_worker_num #851

Closed
leolivier opened this issue Oct 3, 2020 · 31 comments
Closed

worker_id must be less than task_worker_num #851

leolivier opened this issue Oct 3, 2020 · 31 comments
Labels
Milestone

Comments

@leolivier
Copy link

How Shlink is set-up

  • Shlink Version: 2.3.0
  • PHP Version: docker image one
  • How do you serve Shlink: Docker image (stable image on Raspberry Pi, arm/v7)
  • Database engine used: SQLite

Summary

When accessing to a generated short link, I get a 500 error.

Current behavior

When accessing to a generated link, I get a 500 error
and the log shows the following exception

[2020-10-03T10:43:40.941875+00:00] [NULL] Shlink.ERROR - ErrorException: Swoole\Server::task(): worker_id must be less than task_worker_num[16] in /etc/shlink/vendor/shlinkio/shlink-event-dispatcher/src/Listener/AsyncEventListener.php:22
Stack trace:
#0 [internal function]: Laminas\Stratigility\Middleware\ErrorHandler->Laminas\Stratigility\Middleware\{closure}(2, 'Swoole\\Server::...', '/etc/shlink/ven...', 22, Array)
#1 /etc/shlink/vendor/shlinkio/shlink-event-dispatcher/src/Listener/AsyncEventListener.php(22): Swoole\Server->task(Object(Shlinkio\Shlink\EventDispatcher\Listener\EventListenerTask))
#2 /etc/shlink/vendor/phly/phly-event-dispatcher/src/EventDispatcher.php(39): Shlinkio\Shlink\EventDispatcher\Listener\AsyncEventListener->__invoke(Object(Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited))
#3 /etc/shlink/module/Core/src/Service/VisitsTracker.php(48): Phly\EventDispatcher\EventDispatcher->dispatch(Object(Shlinkio\Shlink\Core\EventDispatcher\ShortUrlVisited))
#4 /etc/shlink/module/Core/src/Action/AbstractTrackingAction.php(58): Shlinkio\Shlink\Core\Service\VisitsTracker->track(Object(Shlinkio\Shlink\Core\Entity\ShortUrl), Object(Shlinkio\Shlink\Core\Model\Visitor))
#5 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Shlinkio\Shlink\Core\Action\AbstractTrackingAction->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#6 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#7 /etc/shlink/vendor/akrabat/ip-address-middleware/src/IpAddress.php(91): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#8 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): RKA\Middleware\IpAddress->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#9 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#10 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#11 /etc/shlink/vendor/mezzio/mezzio-router/src/Route.php(101): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#12 /etc/shlink/vendor/mezzio/mezzio-router/src/RouteResult.php(111): Mezzio\Router\Route->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#13 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/DispatchMiddleware.php(36): Mezzio\Router\RouteResult->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#14 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Router\Middleware\DispatchMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#15 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#16 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#17 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#18 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php(48): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#19 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\Middleware\PathMiddlewareDecorator->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#20 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(54): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#21 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/ImplicitHeadMiddleware.php(85): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#22 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Router\Middleware\ImplicitHeadMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#23 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#24 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/RouteMiddleware.php(57): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#25 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Router\Middleware\RouteMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#26 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#27 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#28 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#29 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(54): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#30 /etc/shlink/vendor/shlinkio/shlink-common/src/Middleware/CloseDbConnectionMiddleware.php(27): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#31 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Shlinkio\Shlink\Common\Middleware\CloseDbConnectionMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#32 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#33 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#34 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#35 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php(48): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#36 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\Middleware\PathMiddlewareDecorator->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#37 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(54): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#38 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/ErrorHandler.php(144): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#39 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Laminas\Stratigility\Middleware\ErrorHandler->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#40 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#41 /etc/shlink/vendor/mezzio/mezzio-helpers/src/ContentLengthMiddleware.php(32): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#42 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Helper\ContentLengthMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#43 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#44 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#45 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
#46 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
#47 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(73): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\EmptyPipelineHandler))
#48 /etc/shlink/vendor/mezzio/mezzio-swoole/src/SwooleRequestHandlerRunner.php(244): Laminas\Stratigility\MiddlewarePipe->handle(Object(Laminas\Diactoros\ServerRequest))
#49 {main}
[2020-10-03T10:43:40.947553+00:00] [NULL] Access.ERROR - 192.168.0.8 - - "GET /shlink/FSDpx HTTP/1.1" 500 875

Expected behavior

No exception

How to reproduce

Here is the docker-compose file I use and start with docker-compose up -d. It's using traefik for the routing but I don't think it's linked.

networks:
  shlink-network:
    name: shlink-network
  traefik-network:
    name: traefik-network
services:
  shlink:
    container_name: shlink
    depends_on:
    - traefik
    environment:
      BASE_PATH: /shlink
      GEOLITE_LICENSE_KEY: MGinbtU64pzfFdUt
      SHORT_DOMAIN_HOST: ${DOMAIN}
      SHORT_DOMAIN_SCHEMA: https
    image: shlinkio/shlink:stable
    labels:
      traefik.docker.network: shlink-network
      traefik.enable: 'true'
      traefik.http.routers.shlink.entrypoints: web
      traefik.http.routers.shlink.rule: PathPrefix(`/shlink/`) || Path(`/shlink`)
      traefik.http.routers.shlink.service: shlink
      traefik.http.services.shlink.loadbalancer.server.port: 8080
    networks:
      shlink-network: {}
    restart: unless-stopped
  traefik:
    container_name: traefik
    environment:
    - TRAEFIK_API=true
    - TRAEFIK_DASHBOARD=true
    - TRAEFIK_PROVIDERS_DOCKER=true
    - TRAEFIK_PROVIDERS_DOCKER_ENDPOINT=unix:///var/run/docker.sock
    - TRAEFIK_PROVIDERS_DOCKER_EXPOSEDBYDEFAULT=false
    - TRAEFIK_LOG_LEVEL=DEBUG
    - TRAEFIK_GLOBAL_SENDANONYMOUSUSAGE=false
    - TRAEFIK_ENTRYPOINTS_WEB_ADDRESS=:80
    - TRAEFIK_ENTRYPOINTS_WEBSECURE_ADDRESS=:443
    image: traefik:latest
    labels:
      traefik.enable: 'true'
      traefik.http.middlewares.dashboard-addslash.redirectregex.regex: ^(.*)/dashboard$$
      traefik.http.middlewares.dashboard-addslash.redirectregex.replacement: $${1}/dashboard/
      traefik.http.routers.api.entrypoints: web
      traefik.http.routers.api.middlewares: dashboard-addslash@docker
      traefik.http.routers.api.rule: PathPrefix(`/api/`) || PathPrefix(`/dashboard/`) || Path(`/api`) || Path(`/dashboard`)
      traefik.http.routers.api.service: api@internal
    networks:
      shlink-network: {}
      traefik-network: {}
    ports:
    - 80:80
    - 443:443
    restart: unless-stopped
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro

Then I create a link with e.g.:

$ docker exec -it shlink shlink short-url:generate https://google.com      
Processed long URL: https://google.com
Generated short URL: https://<mydomain>/shlink/zSPry

And when I access the short link, I get the error (whatever the target)

@leolivier leolivier added the bug label Oct 3, 2020
@acelaya
Copy link
Member

acelaya commented Oct 10, 2020

Hey.

I was investigating this, and I have no idea why this happens (in theory it shouldn't).

Swoole, the tool used to serve shlink, allows you to spin up a number of processes used to serve requests and to process background tasks. Each one of them is a worker, and has a worker ID.

When you try to run a background task, swoole enqueues it and then it gets assigned to the first free worker.

Apparently, it is trying to assign it to a non existing worker (like, for example, there is 16 workers and it tried to assign it to the 17 one), which is producing this error.

The problem is that this logic is all handled by swoole internally, so I don't know how to prevent this 🤔.

Maybe there's a bug either in swoole or the library I use to integrate with it. I'll try to reproduce it with that version of shlink (I have a couple of raspberries somewhere), and then with a newer version using updated dependencies, to see if it solves the problem.

@leolivier
Copy link
Author

Hey,
I redownloaded the image from scratch today and was not able to reproduce the issue. So maybe something has been changed and it fixed the issue (or the issue appears randomly).
Now I get a 404 when I try accessing the short urls, I don't understand why and I cant' find any log...

@acelaya
Copy link
Member

acelaya commented Oct 10, 2020

Hey @leolivier. Can you open a new ticket for this?

@acelaya acelaya closed this as completed Oct 10, 2020
@leolivier
Copy link
Author

Hi @acelaya
The issue is back :(
Both issues (this one and #855) seems finally to be linked with traefik:

  • I'm using a base path /shlink
  • If I add a middleware to traefik for striping the prefix (thus /shlink) ==> I finally access shlink without the base path and I get a 404
  • If I remove the striping middleware, I access shlink with the base path and I get a 500 with the worker_id issue above

@acelaya
Copy link
Member

acelaya commented Oct 11, 2020

Yep, I saw about the base path, but I didn't think it had nothing to do.

Also, I'm not really familiar with traefik.

So, to summarize, the 404 issue is probably caused by not passing the prefix to shlink, while you have actually defined it's using a prefix through the BASE_PATH env var.

You have to either make sure the URL keeps the prefix until it reaches shlink and the BASE_PATH is defined, or use something in front of shlink to strip out the prefix and then don't define the BASE_PATH at all.

That probably closes #855

That said, now we still have the issue with the workers, which is most probably related with the architecture in which it is being run. I'll have to investigate further this one.

@leolivier
Copy link
Author

I closed #855, can you reopen this one, please?

@acelaya acelaya reopened this Oct 11, 2020
@acelaya
Copy link
Member

acelaya commented Oct 11, 2020

Reopened. I saw it from the phone and didn't remember I closed it 😅

@acelaya
Copy link
Member

acelaya commented Oct 12, 2020

I think the issue could be related with this swoole/swoole-src#3176

@leolivier
Copy link
Author

Hi @acelaya acelaya, I saw the issue in swoole is closed, any news on your side?

@acelaya
Copy link
Member

acelaya commented Jan 3, 2021

Hey @leolivier

I'm afraid I haven't had time to continue investigting this one. I'm currently focused on pushing v2.5 out. I'll try to make some time after that to investigate a bit more.

The last update is that I wasn't able to reproduce it.

@acelaya
Copy link
Member

acelaya commented Jan 31, 2021

Hey @SidneySun. I received a notification for a comment you posted here, but you seem to have deleted it.

Did you manage to find something out?

Could either you or @leolivier try with the docker image using latest tag? It uses the latest version of swoole. I'm wondering if the issue could have been solved there.

The problem is most probably with swoole, and I have to spend some time setting up a raspberry with docker and such, so any help trying to find out how to report this is more than welcome.

@acelaya acelaya added this to the 2.6.0 milestone Jan 31, 2021
@SidneySun
Copy link

Hi, I have the same problem with Raspberry Pi.
I just provided a log.

Creating fresh database if needed...
Updating database...
Generating proxies...
Clearing entities cache...
[2021-01-31T12:37:20.133129+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 16
[2021-01-31T12:37:20.136317+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 17
[2021-01-31T12:37:20.144139+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 19
[2021-01-31T12:37:20.144139+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 18
[2021-01-31T12:37:20.153088+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 25
[2021-01-31T12:37:20.153213+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 21
[2021-01-31T12:37:20.162114+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 22
[2021-01-31T12:37:20.162114+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 23
[2021-01-31T12:37:20.171842+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 20
[2021-01-31T12:37:20.180491+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 24
[2021-01-31T12:37:20.196927+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 31
[2021-01-31T12:37:20.203095+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 0
[2021-01-31T12:37:20.193086+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 28
[2021-01-31T12:37:20.187461+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 26
[2021-01-31T12:37:20.219527+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 5
[2021-01-31T12:37:20.224093+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 1
[2021-01-31T12:37:20.228723+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 30
[2021-01-31T12:37:20.227835+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 29
[2021-01-31T12:37:20.229910+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 2
[2021-01-31T12:37:20.224093+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 27
[2021-01-31T12:37:20.236515+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 3
[2021-01-31T12:37:20.243738+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 8
[2021-01-31T12:37:20.197386+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 4
[2021-01-31T12:37:20.249603+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 6
[2021-01-31T12:37:20.249603+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 9
[2021-01-31T12:37:20.245284+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 7
[2021-01-31T12:37:20.254193+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 10
[2021-01-31T12:37:20.269165+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 12
[2021-01-31T12:37:20.263953+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 11
[2021-01-31T12:37:20.272559+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 13
[2021-01-31T12:37:20.277305+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 14
[2021-01-31T12:37:20.279609+00:00] [NULL] Access.NOTICE - Worker started in /etc/shlink with ID 15
[2021-01-31T12:38:51.666354+00:00] [NULL] Shlink.ERROR - ErrorException: Swoole\Server::task(): worker_id must be less than task_worker_num[16] in /etc/shlink/vendor/mezzio/mezzio-swoole/src/Task/DeferredServiceListener.php:41

I found that the maximum id of the worker is 32. It is greater than task_worker_num[16].
Five minutes later, I found that it is the sum of task_worker_num and web_worker_num. It is correct. So I deleted that post.

I have tried with the docker image using the latest tag. In fact, I just met this project and pulled the image tonight.

@acelaya
Copy link
Member

acelaya commented Jan 31, 2021

Thanks for clarifying.

The numbers should be correct. Swoole allows setting up some processes that will handle web requests, and some that will handle tasks.

By default, shlink sets up 16 of each. Maybe that's to high for the raspberry.

It can be changed by using the WEB_WORKER_NUM and TASK_WORKER_NUM env vars. Can you try providing smaller numbers to see if it works? Maybe 1 each?

@SidneySun
Copy link

Yes, I have tried smaller numbers yesterday. Because of this, I discovered the quantitative relationship between them.
The settings I have tried are as follows:
WEB_WORKER_NUM = 1 TASK_WORKER_NUM = 32
WEB_WORKER_NUM = 1 TASK_WORKER_NUM = 1
WEB_WORKER_NUM = 0 TASK_WORKER_NUM = 1
WEB_WORKER_NUM = -1 TASK_WORKER_NUM = 1
And some other small numbers.
When WEB_WORK_NUM is set to 0, it will be modified to 4.
When WEB_WORK_NUM is set to -1, it will be modified to 4000+.

All in all, the total number of workers must be greater than task_worker_num.
But I don't think this is the source of the problem.

@acelaya
Copy link
Member

acelaya commented Feb 1, 2021

Ok. Thanks for the help. I'll probably try reporting the issue to the swoole project with this information.

@leolivier
Copy link
Author

Hi, didn't have time to test latest version, will keep you posted when I'll do

@acelaya
Copy link
Member

acelaya commented Feb 1, 2021

Thanks @leolivier

@acelaya
Copy link
Member

acelaya commented Feb 1, 2021

I have finally set-up my old raspberry 2B with some raspbian, installed docker and executed shlink over it.

With stable versions, I can reproduce the issue described here.

However, with latest version, which uses swoole 4.6.2, I get a different error, something related with clock_gettime.

I'll try to report both in swoole project and see how it goes.

@SidneySun
Copy link

Hi, I'm sorry, I used the stable image yesterday.
I got the same problem about clock_gettime when I used the latest image.
I met this kind of problem about time or clock in another project.
An unsafe solution is to add --privileged when you run a container.
For example,

sudo docker run  --name my_shlink  -p 8080:8080  -e SHORT_DOMAIN_HOST=example.com -e SHORT_DOMAIN_SCHEMA=https     -e GEOLITE_LICENSE_KEY=kjh23ljkbndskj345 --privileged shlinkio/shlink

Then, you will find the original error about worker id.

@acelaya
Copy link
Member

acelaya commented Feb 2, 2021

Cool, thanks for checking.

@acelaya
Copy link
Member

acelaya commented Feb 4, 2021

FYI, the issue I opened in swoole project has been closed by a PR, so I imagine it has been fixed.

I subscribed to the project, and I'll test v 4.6.3 once it's out, to check if the error is gone.

@leolivier
Copy link
Author

Thanks Alejandro, keep us posted please

@acelaya
Copy link
Member

acelaya commented Feb 9, 2021

Once this job finishes https://github.com/shlinkio/shlink/actions/runs/552753589, the latest docker image will be using swoole 4.6.3, which in theory solves the issue reported here.

I'll check it tomorrow afternoon after work (it's 11:15pm in my timezone), but feel free to give it a try.

@acelaya
Copy link
Member

acelaya commented Feb 10, 2021

I have just tried, and I can confirm the issue has been fixed 🙂

@acelaya acelaya closed this as completed Feb 10, 2021
@leolivier
Copy link
Author

leolivier commented Feb 10, 2021

Great! Thanks @acelaya, I'll test also this weekend

@acelaya
Copy link
Member

acelaya commented Feb 10, 2021

I have bad news. Swoole 4.6.3 seems to have regression that makes requests to never close.

I'm trying to find a solution to this, but I might have to roll back to v4.6.2 and reopen this.

I'll keep you posted.

@acelaya
Copy link
Member

acelaya commented Feb 11, 2021

I found a quite simple workaround to this issue ☝🏼

This build https://github.com/shlinkio/shlink/runs/1879379513?check_suite_focus=true includes the fix and still uses swoole 4.6.3. No need to rollback anything.

Once that finishes, latest tag of the docker image should no longer fail.

@leolivier
Copy link
Author

Hi @acelaya
Did you push this build on docker hub? Is this version 2.5.2 on shlinkio/shlink:latest updated 14h ago?
I tried today with this version but I'm still getting the same error when accessing a shortened url:

[2021-02-13T14:59:45.658215+00:00] [NULL] Shlink.ERROR - ErrorException: Swoole\Server::task(): worker_id must be less than task_worker_num[16] in /etc/shlink/vendor/mezzio/mezzio-swoole/src/Task/DeferredServiceListener.php:41
�\00\00\00\00\00\00
Stack trace:

#0 [internal function]: Laminas\Stratigility\Middleware\ErrorHandler->Laminas\Stratigility\Middleware\{closure}(2, 'Swoole\\Server::...', '/etc/shlink/ven...', 41, Array)

#1 /etc/shlink/vendor/mezzio/mezzio-swoole/src/Task/DeferredServiceListener.php(41): Swoole\Server->task(Object(Mezzio\Swoole\Task\ServiceBasedTask))

#2 /etc/shlink/vendor/shlinkio/shlink-event-dispatcher/src/Listener/LazyEventListener.php(22): Mezzio\Swoole\Task\DeferredServiceListener->__invoke(Object(Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited))

#3 /etc/shlink/vendor/mezzio/mezzio-swoole/src/Event/EventDispatcher.php(41): Shlinkio\Shlink\EventDispatcher\Listener\LazyEventListener->__invoke(Object(Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited))

#4 /etc/shlink/vendor/shlinkio/shlink-event-dispatcher/src/Dispatcher/EventDispatcherAggregate.php(34): Mezzio\Swoole\Event\EventDispatcher->dispatch(Object(Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited))

#5 /etc/shlink/module/Core/src/Service/VisitsTracker.php(49): Shlinkio\Shlink\EventDispatcher\Dispatcher\EventDispatcherAggregate->dispatch(Object(Shlinkio\Shlink\Core\EventDispatcher\Event\ShortUrlVisited))

#6 /etc/shlink/module/Core/src/Action/AbstractTrackingAction.php(57): Shlinkio\Shlink\Core\Service\VisitsTracker->track(Object(Shlinkio\Shlink\Core\Entity\ShortUrl), Object(Shlinkio\Shlink\Core\Model\Visitor))

#7 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Shlinkio\Shlink\Core\Action\AbstractTrackingAction->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#8 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#9 /etc/shlink/vendor/akrabat/ip-address-middleware/src/IpAddress.php(132): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#10 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): RKA\Middleware\IpAddress->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#11 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#12 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#13 /etc/shlink/vendor/mezzio/mezzio-router/src/Route.php(91): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#14 /etc/shlink/vendor/mezzio/mezzio-router/src/RouteResult.php(103): Mezzio\Router\Route->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#15 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/DispatchMiddleware.php(36): Mezzio\Router\RouteResult->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#16 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Router\Middleware\DispatchMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#17 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#18 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#19 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#20 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php(48): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#21 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\Middleware\PathMiddlewareDecorator->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#22 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(54): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#23 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/ImplicitHeadMiddleware.php(82): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#24 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Router\Middleware\ImplicitHeadMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#25 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#26 /etc/shlink/vendor/mezzio/mezzio-router/src/Middleware/RouteMiddleware.php(56): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#27 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Router\Middleware\RouteMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#28 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#29 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#30 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#31 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(54): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#32 /etc/shlink/vendor/shlinkio/shlink-common/src/Middleware/CloseDbConnectionMiddleware.php(27): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#33 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Shlinkio\Shlink\Common\Middleware\CloseDbConnectionMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#34 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#35 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#36 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#37 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/PathMiddlewareDecorator.php(48): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#38 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\Middleware\PathMiddlewareDecorator->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#39 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(54): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#40 /etc/shlink/vendor/laminas/laminas-stratigility/src/Middleware/ErrorHandler.php(144): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#41 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Laminas\Stratigility\Middleware\ErrorHandler->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#42 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#43 /etc/shlink/vendor/mezzio/mezzio-helpers/src/ContentLengthMiddleware.php(32): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#44 /etc/shlink/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(47): Mezzio\Helper\ContentLengthMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#45 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#46 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#47 /etc/shlink/vendor/laminas/laminas-stratigility/src/Next.php(61): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))

#48 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(84): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))

#49 /etc/shlink/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(73): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\EmptyPipelineHandler))

#50 /etc/shlink/vendor/mezzio/mezzio-swoole/src/Event/RequestHandlerRequestListener.php(121): Laminas\Stratigility\MiddlewarePipe->handle(Object(Laminas\Diactoros\ServerRequest))

#51 /etc/shlink/vendor/mezzio/mezzio-swoole/src/Event/EventDispatcher.php(41): Mezzio\Swoole\Event\RequestHandlerRequestListener->__invoke(Object(Mezzio\Swoole\Event\RequestEvent))

#52 /etc/shlink/vendor/mezzio/mezzio-swoole/src/SwooleRequestHandlerRunner.php(142): Mezzio\Swoole\Event\EventDispatcher->dispatch(Object(Mezzio\Swoole\Event\RequestEvent))

#53 {main}

[2021-02-13T14:59:45.661542+00:00] [NULL] Access.ERROR - 192.168.1.8 - - "GET /shlink/2lMY5 HTTP/1.1" 500 28

@acelaya
Copy link
Member

acelaya commented Feb 13, 2021

Can you share how you run the docker command?

Also, did you run docker pull shlinkio/shlink:latest first? Otherwise, if you had an "older" version locally, it will use that one instead.

@acelaya
Copy link
Member

acelaya commented Feb 13, 2021

I have checked again, just in case I missed something or I have introduced some unintended regression since I tested for the first time, and I can confirm it works.

Swoole tasks are now properly executed when a short URL is visited. I took some pictures.

PXL_20210213_171953588

PXL_20210213_172504419

The best thing is that I have just released v2.6.0, which includes this fix.

As soon as this build finishes, the corresponding docker image will be available.

https://github.com/shlinkio/shlink/actions/runs/564130076

@leolivier
Copy link
Author

I found the solution by looking at your Dockerfile:
You are using alpine 3.13 and there's a big problem between Raspbian and Alpine 3.13. I fell already in 2 issues with totally different symptoms using

  1. a nextcloud image
  2. the official redis image.

And now it's the 3rd one with shlink and yet another symptom...
So, you just need to update libseccomp to a recent version as described in my comment there: redis/docker-library-redis#269 (comment) and magically everything starts working 😜 !!!
I did that on another Pi this morning for redis but didn't think it could be the same problem on this one...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants