roadrunner-server / roadrunner

🤯 High-performance PHP application server, process manager written in Go and powered with plugins
https://docs.roadrunner.dev
MIT License
7.86k stars 409 forks source link

[BUG?, RR1] Unable to connect to worker: invalid data found in the buffer (possible echo) #509

Closed sergey-yabloncev closed 3 years ago

sergey-yabloncev commented 3 years ago

I use RoadRunner for a project on laravel in docker. When I add extension xdebug server not work. But if I remove extension xdebug all working well.

Errortrace, Backtrace or Panictrace

Error: [http]: unable to connect to worker: invalid data found in the buffer (possible echo): signal: killed
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x78 pc=0x949c32]

goroutine 39 [running]:
github.com/spiral/roadrunner.(*StaticPool).Workers(0x0, 0x0, 0x0, 0x0)
    github.com/spiral/roadrunner/static_pool.go:107 +0x52
github.com/spiral/roadrunner.(*Server).Workers(0xc0000e0000, 0x0, 0x0, 0x117e120)
    github.com/spiral/roadrunner/server.go:219 +0x44
github.com/spiral/roadrunner/util.ServerState(0xc0000e0000, 0xc0000e0000, 0xc6e060, 0xc00004bfb8, 0xab45a9, 0xc0003830e0)
    github.com/spiral/roadrunner/util/state.go:53 +0x85
github.com/spiral/roadrunner/cmd/rr/http.(*metricCollector).collectMemory(0xc0000ada60, 0xc000340000, 0x2540be400)
    github.com/spiral/roadrunner/cmd/rr/http/metrics.go:113 +0xba
created by github.com/spiral/roadrunner/cmd/rr/http.init.1.func1
    github.com/spiral/roadrunner/cmd/rr/http/metrics.go:36 +0x293
ERRO[0000] [http]: [http]: unable to connect to worker: invalid data found in the buffer (possible echo): signal: killed 

Dockerfile

# https://hub.docker.com/_/php/
FROM php:8.0-cli-alpine

ENV RR_VERSION 1.9.2

# Install dev dependencies
RUN apk add --no-cache --virtual .build-deps \
    $PHPIZE_DEPS \
    curl-dev \
    libtool \
    libxml2-dev \
    postgresql-dev \
    sqlite-dev \

# Install production dependencies
&& apk add --no-cache \
    bash \
    shadow \
    nano \
    curl \
    wget \
    freetype-dev \
    icu-dev \
    icu-libs \
    libc-dev \
    libjpeg-turbo-dev \
    libpng-dev \
    libzip-dev \
    make \
    oniguruma-dev \
    openssh-client \
    postgresql-libs \
    rsync \
    jpegoptim optipng pngquant gifsicle \
    zlib-dev \

# Install PECL and PEAR extensions
&& pecl install \
    redis \

# Enable PECL and PEAR extensions
&& docker-php-ext-enable \
    redis \

# Configure php extensions
&& docker-php-ext-configure gd --with-freetype --with-jpeg \

# Install php extensions
&& docker-php-ext-install \
    bcmath \
    calendar \
    curl \
    exif \
    gd \
    iconv \
    intl \
    mbstring \
    opcache \
    pdo \
    pdo_pgsql \
    pdo_sqlite \
    pcntl \
    sockets \
    tokenizer \
    xml \
    zip

###########################################################################
# xDebug:
###########################################################################

ARG ENABLE_XDEBUG=false

RUN if [ ${ENABLE_XDEBUG} = true ]; then \
  # Install the xdebug extension
   pecl install xdebug; \
   docker-php-ext-enable xdebug \
;fi

# Copy php.ini configuration
COPY php.ini /usr/local/etc/php/conf.d/40-custom.ini
# Copy opcache.ini configuration
COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini

# Install composer
ENV COMPOSER_HOME /composer
ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer

# Download RoadRunner
RUN mkdir /tmp/rr \
  && cd /tmp/rr \
  && echo "{\"require\":{\"spiral/roadrunner\":\"${RR_VERSION}\"}}" >> composer.json \
  && composer install \
  && vendor/bin/rr get-binary -l /usr/local/bin \
  && rm -rf /tmp/rr

# Cleanup dev dependencies
RUN apk del -f .build-deps && rm -rf /var/cache/apk/* && docker-php-source delete && rm -rf /tmp/pear

RUN usermod -u 1000 www-data && groupmod -g 1000 www-data

WORKDIR /var/www

USER 1000:1000

EXPOSE 80
EXPOSE 443

CMD ["/usr/local/bin/rr", "serve", "-c", "/var/www/.rr.yml", "-w", "/var/www", "-d"]

docker-compose

version: '3'

networks:
  app-network:
    driver: bridge

services:

  app:
    image: app
    container_name: app
    hostname: app-service
    build:
      context: ./docker/php
      dockerfile: Dockerfile
      args:
        ENABLE_XDEBUG: ${DOCKER_PHP_ENABLE_XDEBUG:-false}
        PHP_IDE_CONFIG: serverName=localhost
        XDEBUG_CONFIG: client_host=172.17.0.1 mode=debug idekey='PHPSTORM'
    restart: unless-stopped
    volumes:
      - ./:/var/www:cached
    ports:
      - "${DOCKER_NGINX_PORT:-80}:80"
      - "${DOCKER_NGINX_PORT_HTTPS:-443}:443"
      - "2112:2112"
      - "2113:2113"
    networks:
      - app-network

.rr.yaml

# rpc bus allows php application and external clients to talk to rr services.
rpc:
  # enable rpc server
  enable: true
  # rpc connection DSN. Supported TCP and Unix sockets.
  listen: tcp://:6001

metrics:
  # prometheus client address (path /metrics added automatically)
  address: 0.0.0.0:2112

  # list of metrics to collect from application
  collect:
    # metric name
    app_metric:
      # type [gauge, counter, histogram, summary]
      type: histogram
      # short description
      help: "Custom application metric"
      # metric groups/tags
      labels: [ "type" ]
      # for histogram only
      buckets: [ 0.1, 0.2, 0.3, 1.0 ]
      # objectives defines the quantile rank estimates with their respective
      # absolute error [ for summary only ]
      objectives:
        - 1.4: 2.3
        - 2.0: 1.4

# http service configuration.
http:
  # http host to listen.
  address: 0.0.0.0:80
  ssl:
    # custom https port (default 443)
    port:     443
    # force redirect to https connection
    redirect: false
    # ssl cert
#    cert:     server.crt
    # ssl private key
#    key:      server.key
    # rootCA certificate
#    rootCa:   root.crt

  # max POST request size, including file uploads in MB.
  maxRequestSize: 200

  # file upload configuration.
  uploads:
    # list of file extensions which are forbidden for uploading.
    forbid: [ ".php", ".exe", ".bat" ]

  # cidr blocks which can set ip using X-Real-Ip or X-Forwarded-For
  trustedSubnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]

  # http worker pool configuration.
  workers:
    # php worker command.
    #
    # Allowed arguments:
    # - `--(not-)force-https`
    # - `--(not-)reset-db-connections`
    # - `--(not-)reset-redis-connections`
    # - `--(not-)refresh-app`
    # - `--(not-)inject-stats-into-request`
    # - `--not-fix-symfony-file-validation`

#    command: "php ./vendor/bin/rr-worker --refresh-app --reset-redis-connections"
    command: "php ./vendor/bin/rr-worker --reset-redis-connections"
    # connection method (pipes, tcp://:9000, unix://socket.unix). default "pipes"
    relay: "pipes"
    # user under which process will be started
    user: ""
    # worker pool configuration.
    pool:
      # number of workers to be serving.
      numWorkers: 16
      # maximum jobs per worker, 0 - unlimited.
      maxJobs: 64
      # for how long worker is allowed to be bootstrapped.
      allocateTimeout: 60
      # amount of time given to worker to gracefully destruct itself.
      destroyTimeout: 60

# Additional HTTP headers and CORS control.
headers:
  # Middleware to handle CORS requests, https://www.w3.org/TR/cors/
  cors:
    # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
    allowedOrigin: "*"
    # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
    allowedHeaders: "*"
    # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
    allowedMethods: "GET,POST,PUT,DELETE"
    # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
    allowCredentials: true

    exposedHeaders: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma"
    # Max allowed age in seconds
    maxAge: 600

  # Automatically add headers to every request passed to PHP.
  request:
#    "Example-Request-Header": "Value"
  # Automatically add headers to every response.
  response:
    "X-Powered-By": "RoadRunner"

# monitors rr server(s)
limit:
  # check worker state each second
  interval: 1

  # custom watch configuration for each service
  services:
    # monitor http workers
    http:
      # maximum allowed memory consumption per worker (soft)
      maxMemory: 100
      # maximum time to live for the worker (soft)
      TTL: 0

      # maximum allowed amount of time worker can spend in idle before being removed (for weak db connections, soft)
      idleTTL: 0
      # max_execution_time (brutal)
      execTTL: 60

# static file serving. remove this section to disable static file serving.
static:
  # root directory for static file (http would not serve .php and .htaccess files).
  dir: "public"
  # list of extensions for forbid for serving.
  forbid: [ ".php", ".htaccess" ]
  # Automatically add headers to every request.
  request:
#    "Example-Request-Header": "Value"
  # Automatically add headers to every response.
  response:
    "X-Powered-By": "RoadRunner"

# health service configuration
health:
  # http host to serve health requests.
  address: 0.0.0.0:2113

# reload can reset rr servers when files change
reload:
  # refresh internval (default 1s)
  interval: 1s
  # file extensions to watch, defaults to [.php]
  patterns: [ ".php" ]

  # list of services to watch
  services:
    http:
      # list of dirs, "" root
      dirs: [ "" ]
      # include sub directories
      recursive: true

System information

PHP version 8,0,1 roadrunner-laravel 3.7 RoadRunner version 1.9.2 Environment docker

wolfy-j commented 3 years ago

Does manual php worker.php work and does not produce any output until you type anything in CLI?

Check Troubleshooting here https://roadrunner.dev/docs/php-worker

sergey-yabloncev commented 3 years ago

if you log in to the container and run it in manual mode

bash-5.1$ php ./vendor/bin/rr-worker

Warning: JIT is incompatible with third party extensions that override zend_execute_ex(). JIT disabled. in Unknown on line 0

if start server

bash-5.1$ //usr/local/bin/rr serve -c /var/www/.rr.yml -w /var/www -d
ERRO[0000] [http]: [http]: unable to connect to worker: invalid data found in the buffer (possible echo): signal: killed 
Error: [http]: unable to connect to worker: invalid data found in the buffer (possible echo): signal: killed
sergey-yabloncev commented 3 years ago

if disable JIT in PHP, all work well, but I think its not correct behavior. If start script in PHP CLI JIT disabled and we see the warning

wolfy-j commented 3 years ago

Sounds like your version of xDebug conflicts with JIT, RR has nothing to do with it. But such behavior breaks the communication protocol. You can try to use Unix pipes but the problem still is there.

sergey-yabloncev commented 3 years ago

Thank's!

rustatian commented 3 years ago

@sergey-yabloncev If your problem was solved, feel free to close the issue :)