From 44e2cb8c34ed8b79cb14eee764d482a8526f4d37 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 28 Nov 2024 15:13:15 +0100 Subject: [PATCH] Add patch and test job for starvation on bigger SSL records --- .github/workflows/binary-gems.yml | 237 ++++++++------ .github/workflows/source-gem.yml | 304 +++++++++--------- misc/yugabyte/Dockerfile | 9 + misc/yugabyte/docker-compose.yml | 28 ++ misc/yugabyte/pg-test.rb | 45 +++ ...ffered-SSL-read-bytes-to-support-rec.patch | 52 +++ 6 files changed, 416 insertions(+), 259 deletions(-) create mode 100644 misc/yugabyte/Dockerfile create mode 100644 misc/yugabyte/docker-compose.yml create mode 100644 misc/yugabyte/pg-test.rb create mode 100644 ports/patches/postgresql/17.2/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch diff --git a/.github/workflows/binary-gems.yml b/.github/workflows/binary-gems.yml index 4779569d5..4a1ad77cf 100644 --- a/.github/workflows/binary-gems.yml +++ b/.github/workflows/binary-gems.yml @@ -15,9 +15,9 @@ jobs: fail-fast: false matrix: include: - - platform: "x64-mingw-ucrt" - - platform: "x64-mingw32" - - platform: "x86-mingw32" + # - platform: "x64-mingw-ucrt" + # - platform: "x64-mingw32" + # - platform: "x86-mingw32" - platform: "x86_64-linux" steps: - uses: actions/checkout@v4 @@ -43,112 +43,134 @@ jobs: name: binary-gem-${{ matrix.platform }} path: pkg/*.gem - job_test_binary: - name: Test + # job_test_binary: + # name: Test + # needs: rcd_build + # strategy: + # fail-fast: false + # matrix: + # include: + # - os: windows-latest + # ruby: "3.3" + # platform: "x64-mingw-ucrt" + # - os: windows-latest + # ruby: "3.1.4-1" + # platform: "x86-mingw32" + # PGVERSION: 10.20-1-windows + # - os: windows-latest + # ruby: "2.7" + # platform: "x64-mingw32" + # PGVERSION: 16.6-1-windows-x64 + # - os: ubuntu-latest + # ruby: "3.2" + # platform: "x86_64-linux" + # + # runs-on: ${{ matrix.os }} + # env: + # PGVERSION: ${{ matrix.PGVERSION }} + # steps: + # - uses: actions/checkout@v4 + # - name: Set up Ruby + # if: matrix.platform != 'x86-mingw32' + # uses: ruby/setup-ruby-pkgs@v1 + # with: + # ruby-version: ${{ matrix.ruby }} + # apt-get: "postgresql" # Ubuntu + # brew: "postgresql" # macOS + # mingw: "postgresql" # Windows mingw / mswin /ucrt + # + # - name: Set up 32 bit x86 Ruby + # if: matrix.platform == 'x86-mingw32' + # run: | + # $(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-${{ matrix.ruby }}/rubyinstaller-${{ matrix.ruby }}-x86.exe", "$pwd/ruby-setup.exe") + # cmd /c ruby-setup.exe /currentuser /verysilent /dir=C:/Ruby-${{ matrix.ruby }} + # echo "c:/ruby-${{ matrix.ruby }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + # + # c:/ruby-${{ matrix.ruby }}/bin/ridk enable + # c:/msys64/usr/bin/bash -lc "pacman -S --noconfirm --needed make `${MINGW_PACKAGE_PREFIX}-pkgconf `${MINGW_PACKAGE_PREFIX}-libyaml `${MINGW_PACKAGE_PREFIX}-gcc `${MINGW_PACKAGE_PREFIX}-make" + # echo "C:/msys64/$env:MSYSTEM_PREFIX/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + # + # - name: Download gem from build job + # uses: actions/download-artifact@v4 + # with: + # name: binary-gem-${{ matrix.platform }} + # + # - name: Download PostgreSQL 32-bit + # if: ${{ matrix.os == 'windows-latest' && matrix.PGVERSION }} + # run: | + # Add-Type -AssemblyName System.IO.Compression.FileSystem + # function Unzip { + # param([string]$zipfile, [string]$outpath) + # [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) + # } + # $(new-object net.webclient).DownloadFile("http://get.enterprisedb.com/postgresql/postgresql-$env:PGVERSION-binaries.zip", "postgresql-binaries.zip") + # Unzip "postgresql-binaries.zip" "." + # echo "$pwd/pgsql/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + # + # - name: set PGUSER + # if: ${{ matrix.os == 'windows-latest' }} + # run: | + # echo "PGUSER=$env:USERNAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + # echo "PGPASSWORD=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + # + # - run: echo $env:PATH + # - run: gem update --system 3.3.26 + # - run: bundle install + # - run: gem install --local pg-*${{ matrix.platform }}.gem --verbose + # - name: Run specs + # if: ${{ matrix.os != 'windows-latest' }} + # run: ruby -rpg -S rspec -fd spec/**/*_spec.rb + # - name: Run specs + # if: ${{ matrix.os == 'windows-latest' }} + # run: | + # ridk enable + # ruby -rpg -S rspec -fd spec/**/*_spec.rb + # + # - name: Print logs if job failed + # if: ${{ failure() && matrix.os == 'windows-latest' }} + # run: | + # ridk enable + # find "$(ruby -e"puts RbConfig::CONFIG[%q[libdir]]")" -name mkmf.log -print0 | xargs -0 cat + # find -name setup.log -print0 | xargs -0 cat + # + # + # job_binary_multiarch: + # name: multiarch (${{matrix.platform}} on ${{matrix.from_image}} ${{matrix.image_platform}}) + # needs: rcd_build + # strategy: + # fail-fast: false + # matrix: + # include: + # - from_image: fedora:39 + # image_platform: linux/x86_64 + # gem_platform: x86_64-linux + # dockerfile: centos + # - from_image: alpine + # image_platform: linux/x86_64 + # gem_platform: x86_64-linux + # dockerfile: alpine + # + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - name: Download gem-${{ matrix.gem_platform }} + # uses: actions/download-artifact@v4 + # with: + # name: binary-gem-${{ matrix.gem_platform }} + # - name: Build image and Run tests + # run: | + # docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + # docker build --rm --platform ${{matrix.image_platform}} --build-arg from_image=${{matrix.from_image}} -t ruby-test -f spec/env/Dockerfile.${{matrix.dockerfile}} . + # docker run --rm -t --network=host -v `pwd`:/build ruby-test + + job_binary_yugabyte: + name: yugabyte (${{matrix.gem_platform}} needs: rcd_build strategy: fail-fast: false matrix: include: - - os: windows-latest - ruby: "3.3" - platform: "x64-mingw-ucrt" - - os: windows-latest - ruby: "3.1.4-1" - platform: "x86-mingw32" - PGVERSION: 10.20-1-windows - - os: windows-latest - ruby: "2.7" - platform: "x64-mingw32" - PGVERSION: 16.6-1-windows-x64 - - os: ubuntu-latest - ruby: "3.2" - platform: "x86_64-linux" - - runs-on: ${{ matrix.os }} - env: - PGVERSION: ${{ matrix.PGVERSION }} - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - if: matrix.platform != 'x86-mingw32' - uses: ruby/setup-ruby-pkgs@v1 - with: - ruby-version: ${{ matrix.ruby }} - apt-get: "postgresql" # Ubuntu - brew: "postgresql" # macOS - mingw: "postgresql" # Windows mingw / mswin /ucrt - - - name: Set up 32 bit x86 Ruby - if: matrix.platform == 'x86-mingw32' - run: | - $(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-${{ matrix.ruby }}/rubyinstaller-${{ matrix.ruby }}-x86.exe", "$pwd/ruby-setup.exe") - cmd /c ruby-setup.exe /currentuser /verysilent /dir=C:/Ruby-${{ matrix.ruby }} - echo "c:/ruby-${{ matrix.ruby }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - c:/ruby-${{ matrix.ruby }}/bin/ridk enable - c:/msys64/usr/bin/bash -lc "pacman -S --noconfirm --needed make `${MINGW_PACKAGE_PREFIX}-pkgconf `${MINGW_PACKAGE_PREFIX}-libyaml `${MINGW_PACKAGE_PREFIX}-gcc `${MINGW_PACKAGE_PREFIX}-make" - echo "C:/msys64/$env:MSYSTEM_PREFIX/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - - name: Download gem from build job - uses: actions/download-artifact@v4 - with: - name: binary-gem-${{ matrix.platform }} - - - name: Download PostgreSQL 32-bit - if: ${{ matrix.os == 'windows-latest' && matrix.PGVERSION }} - run: | - Add-Type -AssemblyName System.IO.Compression.FileSystem - function Unzip { - param([string]$zipfile, [string]$outpath) - [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) - } - $(new-object net.webclient).DownloadFile("http://get.enterprisedb.com/postgresql/postgresql-$env:PGVERSION-binaries.zip", "postgresql-binaries.zip") - Unzip "postgresql-binaries.zip" "." - echo "$pwd/pgsql/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - - name: set PGUSER - if: ${{ matrix.os == 'windows-latest' }} - run: | - echo "PGUSER=$env:USERNAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - echo "PGPASSWORD=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - - - run: echo $env:PATH - - run: gem update --system 3.3.26 - - run: bundle install - - run: gem install --local pg-*${{ matrix.platform }}.gem --verbose - - name: Run specs - if: ${{ matrix.os != 'windows-latest' }} - run: ruby -rpg -S rspec -fd spec/**/*_spec.rb - - name: Run specs - if: ${{ matrix.os == 'windows-latest' }} - run: | - ridk enable - ruby -rpg -S rspec -fd spec/**/*_spec.rb - - - name: Print logs if job failed - if: ${{ failure() && matrix.os == 'windows-latest' }} - run: | - ridk enable - find "$(ruby -e"puts RbConfig::CONFIG[%q[libdir]]")" -name mkmf.log -print0 | xargs -0 cat - find -name setup.log -print0 | xargs -0 cat - - - job_binary_multiarch: - name: multiarch (${{matrix.platform}} on ${{matrix.from_image}} ${{matrix.image_platform}}) - needs: rcd_build - strategy: - fail-fast: false - matrix: - include: - - from_image: fedora:39 - image_platform: linux/x86_64 - gem_platform: x86_64-linux - dockerfile: centos - - from_image: alpine - image_platform: linux/x86_64 - gem_platform: x86_64-linux - dockerfile: alpine + - gem_platform: x86_64-linux runs-on: ubuntu-latest steps: @@ -159,6 +181,7 @@ jobs: name: binary-gem-${{ matrix.gem_platform }} - name: Build image and Run tests run: | - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker build --rm --platform ${{matrix.image_platform}} --build-arg from_image=${{matrix.from_image}} -t ruby-test -f spec/env/Dockerfile.${{matrix.dockerfile}} . - docker run --rm -t --network=host -v `pwd`:/build ruby-test + sudo apt-get install -y docker-compose + cp -v pg-*.gem misc/yugabyte/ + cd misc/yugabyte + docker-compose up --abort-on-container-exit --exit-code-from pg diff --git a/.github/workflows/source-gem.yml b/.github/workflows/source-gem.yml index bc29b5e6f..834b0dbda 100644 --- a/.github/workflows/source-gem.yml +++ b/.github/workflows/source-gem.yml @@ -1,152 +1,152 @@ -name: Source gem -on: - workflow_dispatch: - schedule: - - cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3 - push: - branches: - - master - tags: - - "*.*.*" - pull_request: - types: [opened, synchronize] - branches: - - "*" -permissions: - contents: read - -jobs: - job_build_gem: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: "3.2" - - - name: Build source gem - run: gem build pg.gemspec - - - name: Upload source gem - uses: actions/upload-artifact@v4 - with: - name: source-gem - path: "*.gem" - - job_test_gem: - name: Test - needs: job_build_gem - strategy: - fail-fast: false - matrix: - include: - - os: windows - ruby: "head" - PGVERSION: 17.0-1-windows-x64 - PGVER: "17" - - os: windows - ruby: "2.7" - PGVERSION: 10.20-1-windows-x64 - PGVER: "10" - - os: windows - ruby: "mswin" - PGVERSION: 17.0-1-windows-x64 - PGVER: "17" - - os: ubuntu - ruby: "head" - PGVER: "17" - - os: ubuntu - ruby: "3.2" - PGVER: "12" - - os: ubuntu - os_ver: "20.04" - ruby: "2.7" - PGVER: "10" - - os: ubuntu - ruby: "truffleruby" - PGVER: "14" - - os: ubuntu - ruby: "truffleruby-head" - PGVER: "17" - - os: macos - ruby: "head" - PGVERSION: 17.0-1-osx - PGVER: "17" - - runs-on: ${{ matrix.os }}-${{ matrix.os_ver || 'latest' }} - env: - PGVERSION: ${{ matrix.PGVERSION }} - PGVER: ${{ matrix.PGVER }} - MAKE: make -j2 V=1 - - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - - - name: Download gem from build job - uses: actions/download-artifact@v4 - with: - name: source-gem - - - name: Install required packages Windows - if: matrix.os == 'windows' && matrix.ruby != 'mswin' - shell: cmd - run: ridk exec sh -c "pacman --sync --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc" - - - name: Download PostgreSQL Windows - if: matrix.os == 'windows' - run: | - Add-Type -AssemblyName System.IO.Compression.FileSystem - function Unzip { - param([string]$zipfile, [string]$outpath) - [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) - } - - $(new-object net.webclient).DownloadFile("http://get.enterprisedb.com/postgresql/postgresql-$env:PGVERSION-binaries.zip", "postgresql-binaries.zip") - Unzip "postgresql-binaries.zip" "." - echo "$pwd/pgsql/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - echo "PGUSER=$env:USERNAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - echo "PGPASSWORD=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - - - name: Download PostgreSQL Ubuntu - if: matrix.os == 'ubuntu' - run: | - echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PGVER" | sudo tee -a /etc/apt/sources.list.d/pgdg.list - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - sudo apt-get -y update - sudo apt-get -y --allow-downgrades install postgresql-$PGVER libpq5=$PGVER* libpq-dev=$PGVER* - echo /usr/lib/postgresql/$PGVER/bin >> $GITHUB_PATH - - - name: Download PostgreSQL Macos - if: matrix.os == 'macos' - run: | - wget https://get.enterprisedb.com/postgresql/postgresql-$PGVERSION-binaries.zip && \ - sudo mkdir -p /Library/PostgreSQL && \ - sudo unzip postgresql-$PGVERSION-binaries.zip -d /Library/PostgreSQL/$PGVER && \ - sudo mv /Library/PostgreSQL/$PGVER/pgsql/* /Library/PostgreSQL/$PGVER/ && \ - echo /Library/PostgreSQL/$PGVER/bin >> $GITHUB_PATH - - - run: gem update --system 3.3.26 - - run: bundle install - - - run: gem install --local *.gem --verbose - - - name: Run specs - env: - PG_DEBUG: 0 - # Temprary fix only for Truffleruby-24.0.0: - TRUFFLERUBYOPT: --experimental-options --keep-handles-alive - run: ruby -rpg -S rspec spec/**/*_spec.rb -cfdoc - - - name: Print logs if job failed - if: ${{ failure() && matrix.os == 'windows' }} - run: ridk exec cat tmp_test_specs/*.log - - - name: Print logs if job failed - if: ${{ failure() && matrix.os != 'windows' }} - run: cat tmp_test_specs/*.log +# name: Source gem +# on: +# workflow_dispatch: +# schedule: +# - cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3 +# push: +# branches: +# - master +# tags: +# - "*.*.*" +# pull_request: +# types: [opened, synchronize] +# branches: +# - "*" +# permissions: +# contents: read +# +# jobs: +# job_build_gem: +# name: Build +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v4 +# - name: Set up Ruby +# uses: ruby/setup-ruby@v1 +# with: +# ruby-version: "3.2" +# +# - name: Build source gem +# run: gem build pg.gemspec +# +# - name: Upload source gem +# uses: actions/upload-artifact@v4 +# with: +# name: source-gem +# path: "*.gem" +# +# job_test_gem: +# name: Test +# needs: job_build_gem +# strategy: +# fail-fast: false +# matrix: +# include: +# - os: windows +# ruby: "head" +# PGVERSION: 17.0-1-windows-x64 +# PGVER: "17" +# - os: windows +# ruby: "2.7" +# PGVERSION: 10.20-1-windows-x64 +# PGVER: "10" +# - os: windows +# ruby: "mswin" +# PGVERSION: 17.0-1-windows-x64 +# PGVER: "17" +# - os: ubuntu +# ruby: "head" +# PGVER: "17" +# - os: ubuntu +# ruby: "3.2" +# PGVER: "12" +# - os: ubuntu +# os_ver: "20.04" +# ruby: "2.7" +# PGVER: "10" +# - os: ubuntu +# ruby: "truffleruby" +# PGVER: "14" +# - os: ubuntu +# ruby: "truffleruby-head" +# PGVER: "17" +# - os: macos +# ruby: "head" +# PGVERSION: 17.0-1-osx +# PGVER: "17" +# +# runs-on: ${{ matrix.os }}-${{ matrix.os_ver || 'latest' }} +# env: +# PGVERSION: ${{ matrix.PGVERSION }} +# PGVER: ${{ matrix.PGVER }} +# MAKE: make -j2 V=1 +# +# steps: +# - uses: actions/checkout@v4 +# - name: Set up Ruby +# uses: ruby/setup-ruby@v1 +# with: +# ruby-version: ${{ matrix.ruby }} +# +# - name: Download gem from build job +# uses: actions/download-artifact@v4 +# with: +# name: source-gem +# +# - name: Install required packages Windows +# if: matrix.os == 'windows' && matrix.ruby != 'mswin' +# shell: cmd +# run: ridk exec sh -c "pacman --sync --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc" +# +# - name: Download PostgreSQL Windows +# if: matrix.os == 'windows' +# run: | +# Add-Type -AssemblyName System.IO.Compression.FileSystem +# function Unzip { +# param([string]$zipfile, [string]$outpath) +# [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) +# } +# +# $(new-object net.webclient).DownloadFile("http://get.enterprisedb.com/postgresql/postgresql-$env:PGVERSION-binaries.zip", "postgresql-binaries.zip") +# Unzip "postgresql-binaries.zip" "." +# echo "$pwd/pgsql/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append +# echo "PGUSER=$env:USERNAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append +# echo "PGPASSWORD=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append +# +# - name: Download PostgreSQL Ubuntu +# if: matrix.os == 'ubuntu' +# run: | +# echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PGVER" | sudo tee -a /etc/apt/sources.list.d/pgdg.list +# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - +# sudo apt-get -y update +# sudo apt-get -y --allow-downgrades install postgresql-$PGVER libpq5=$PGVER* libpq-dev=$PGVER* +# echo /usr/lib/postgresql/$PGVER/bin >> $GITHUB_PATH +# +# - name: Download PostgreSQL Macos +# if: matrix.os == 'macos' +# run: | +# wget https://get.enterprisedb.com/postgresql/postgresql-$PGVERSION-binaries.zip && \ +# sudo mkdir -p /Library/PostgreSQL && \ +# sudo unzip postgresql-$PGVERSION-binaries.zip -d /Library/PostgreSQL/$PGVER && \ +# sudo mv /Library/PostgreSQL/$PGVER/pgsql/* /Library/PostgreSQL/$PGVER/ && \ +# echo /Library/PostgreSQL/$PGVER/bin >> $GITHUB_PATH +# +# - run: gem update --system 3.3.26 +# - run: bundle install +# +# - run: gem install --local *.gem --verbose +# +# - name: Run specs +# env: +# PG_DEBUG: 0 +# # Temprary fix only for Truffleruby-24.0.0: +# TRUFFLERUBYOPT: --experimental-options --keep-handles-alive +# run: ruby -rpg -S rspec spec/**/*_spec.rb -cfdoc +# +# - name: Print logs if job failed +# if: ${{ failure() && matrix.os == 'windows' }} +# run: ridk exec cat tmp_test_specs/*.log +# +# - name: Print logs if job failed +# if: ${{ failure() && matrix.os != 'windows' }} +# run: cat tmp_test_specs/*.log diff --git a/misc/yugabyte/Dockerfile b/misc/yugabyte/Dockerfile new file mode 100644 index 000000000..330215241 --- /dev/null +++ b/misc/yugabyte/Dockerfile @@ -0,0 +1,9 @@ +FROM yugabytedb/yugabyte:2024.1.0.0-b129 + +WORKDIR /app + +RUN yugabyted cert generate_server_certs --hostnames=127.0.0.1 --base_dir=. + +ENTRYPOINT ["yugabyted"] +CMD ["start", "--background", "false", "--ui", "false", "--tserver_flags", "use_client_to_server_encryption=true,cert_node_filename=127.0.0.1,certs_dir=/app/generated_certs/127.0.0.1"] +VOLUME /app diff --git a/misc/yugabyte/docker-compose.yml b/misc/yugabyte/docker-compose.yml new file mode 100644 index 000000000..03d4560cc --- /dev/null +++ b/misc/yugabyte/docker-compose.yml @@ -0,0 +1,28 @@ +services: + yb: + build: . + container_name: yb + ports: + - "127.0.0.1:5433:5433" + volumes: + - certs:/app/generated_certs + healthcheck: + test: 'ysqlsh -h $$(hostname) -c \\conninfo || exit 1;' + interval: 2s + timeout: 30s + retries: 20 + start_period: 10s + + pg: + image: ruby:3.0 + working_dir: /app + volumes: + - .:/app + - certs:/generated_certs + command: bash -c "gem inst pg-*.gem && ruby pg-test.rb" + depends_on: + yb: + condition: service_healthy + +volumes: + certs: diff --git a/misc/yugabyte/pg-test.rb b/misc/yugabyte/pg-test.rb new file mode 100644 index 000000000..d292537da --- /dev/null +++ b/misc/yugabyte/pg-test.rb @@ -0,0 +1,45 @@ +require 'pg' + +conn = PG.connect( + host: 'yb', + port: 5433, + user: 'yugabyte', + dbname: 'yugabyte', + sslmode: 'require', + sslrootcert: 'app/generated_certs/127.0.0.1/ca.crt', + sslcert: 'app/generated_certs/127.0.0.1/node.127.0.0.1.crt', + sslkey: 'app/generated_certs/127.0.0.1/node.127.0.0.1.key' +) + +$stdout.sync = true +# fd = File.open("pg_trace.log", "a+") +# conn.trace(fd) + +begin + # Validate connection is working + res = conn.exec("SELECT version();") + res.each_row do |row| + puts "You are connected to: #{row[0]}" + end +# 53*511 +# 53*767 +# 53*1023 +# 53*1279 +# 7*1817 +# 11*1487 +# 13*1363 +# 16*1211 +# 18*1128 +# 22*1984 +# 27*1723 + + (22..53).each do |m| + (1..2048).each do |l| + hanging_query = "SELECT lpad(''::text, #{m}, '0') FROM generate_series(1, #{l});" + puts "Executing hanging query: #{hanging_query}" + conn.exec(hanging_query) + end + end +ensure + conn.close if conn +end diff --git a/ports/patches/postgresql/17.2/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch b/ports/patches/postgresql/17.2/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch new file mode 100644 index 000000000..3d6818132 --- /dev/null +++ b/ports/patches/postgresql/17.2/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch @@ -0,0 +1,52 @@ +From ab793829a4ce473f1cc2bbc0e2a6f6753553255d Mon Sep 17 00:00:00 2001 +From: Lars Kanis +Date: Sun, 8 Sep 2024 13:59:05 +0200 +Subject: [PATCH] libpq: Process buffered SSL read bytes to support records + >8kB on async API + +The async API of libpq doesn't support SSL record sizes >8kB so far. +This size isn't exceeded by vanilla PostgreSQL, but by other products using +the postgres wire protocol 3. +PQconsumeInput() reads all data readable from the socket, so that the read +condition is cleared. +But it doesn't process all the data that is pending on the SSL layer. +Also a subsequent call to PQisBusy() doesn't process it, so that the client +is triggered to wait for more readable data on the socket. +But this never arrives, so that the connection blocks infinitely. + +To fix this issue call pqReadData() repeatedly until there is no buffered +SSL data left to be read. + +The synchronous libpq API isn't affected, since it supports arbitrary SSL +record sizes already. +--- + src/interfaces/libpq/fe-exec.c | 13 +++++++++++++ + 1 file changed, 13 insertions(+) + +diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c +index 0d224a852..637894ee1 100644 +--- a/src/interfaces/libpq/fe-exec.c ++++ b/src/interfaces/libpq/fe-exec.c +@@ -2006,6 +2006,19 @@ PQconsumeInput(PGconn *conn) + if (pqReadData(conn) < 0) + return 0; + ++ #ifdef USE_SSL ++ /* ++ * Ensure all buffered read bytes in the SSL library are processed, ++ * which might be not the case, if the SSL record size exceeds 8k. ++ * Otherwise parseInput can't process the data. ++ */ ++ while (conn->ssl_in_use && pgtls_read_pending(conn)) ++ { ++ if (pqReadData(conn) < 0) ++ return 0; ++ } ++ #endif ++ + /* Parsing of the data waits till later. */ + return 1; + } +-- +2.43.0 +