Push nuget package to Github.com: The response ended prematurely.An error occurred while sending the request

I’m trying to push NuGet packages to Github.com. I’ve successfully configured an action to build, test and push a .NET Standard package:

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1.5.0
      with:
        dotnet-version: 3.1.301
        # Authenticates packages to push to GPR
        source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
      env:
        NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'

    - name: Install dependencies
      run: dotnet restore

    - name: Build
      run: dotnet build --configuration Release --no-restore

    - name: Test
      run: dotnet test --no-restore --verbosity normal

    - name: Pack
      run: dotnet pack --no-build --configuration Release MintPlayer.SeasonChecker/MintPlayer.SeasonChecker.csproj --output .

    - name: PushNuget
      run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate

    - name: PushGithub
      run: dotnet nuget push *.nupkg --no-symbols --skip-duplicate
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}

The package I’m trying to push now, is a multi-target nuget package, but that shouldn’t really matter. My workflow for this other package is the following:

name: .NET Core

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1.5.0
      with:
        dotnet-version: 3.1.301
        # Authenticates packages to push to GPR
        source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
      env:
        NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
    
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1.0.1
    
    - name: Install dependencies
      run: msbuild /t:Restore
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}
    
    - name: Build
      run: msbuild /t:Pack /p:Configuration=Debug Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj
    
    - name: Copy
      run: copy Library/MintPlayer.MVVM/bin/Debug/*.nupkg .
    
    - name: PushNuget
      run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
    - name: PushGithub
      run: dotnet nuget push *.nupkg --no-symbols --skip-duplicate
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}

So to build the package, I’m using MSBuild, but to push the package I’m still using the ordinary dotnet commands. The push to nuget.org works fine, but the push to Github.com fails with the following error:

An error was encountered when fetching 'PUT https://nuget.pkg.github.com/MintPlayer/'. The request will now be retried.
An error occurred while sending the request.
The response ended prematurely.
PUT https://nuget.pkg.github.com/MintPlayer/

Why is this push to my GitHub feed failing?

I’ve narrowed down the issue.

I’m testing with the same repository, same code, same state. On each test, I’m incrementing the Nuget version of my package. Sometimes it succeeds in pushing to GPR, but most of the time it fails to push the new package.

Pushing to nuget.org has never been a problem in my tests, Pushing to github.com sometimes works, but mostly fails.

So what exactly is going on here?

In my case, the answer has been most of the time in the content of the PackageReleaseNotes tag, by using characters like (, ), ' has caused the publication of the package failed.

1 Like

Thanks for the tip. However I removed the PackageReleaseNotes tag now and it’s still only working once in a whiile.

I have enabled diagnostic output and can see that the workflow actually pulls the github.token from the workflow, so authentication should also not be an issue.

Successful push:

Failed push:


I also tried swapping the Github/Nuget push but the workflow still fails on PushGithub most of the time.

Hi @PieterjanDeClippel,

This appears to be an issue with Transfer-Encoding: chunked HTTP requests. I tried tweaking the NuGet source to not use chunked encoding and the push works every time!

Bizarrely it does work with nuget.exe on the .NET framework, which also claims to use Transfer-Encoding: chunked. My hunch is that this sends the payload as a single chunk.

Could you try modifying your workflow to do this:

    - name: PushGithub
      run: nuget.exe push *.nupkg --no-symbols --skip-duplicate
      env:
        NUGET_AUTH_TOKEN: ${{ github.token }}

You should find this will work consistently.

Please let me know how you get on!

1 Like

Thanks for the response.

I’ve tried using nuget.exe instead. It has run a first time and made a successful push. I’ll need to try some more pushes to draw a definite conclusion.

I have to note however that I’ve got a similar setup with a pure .NET Standard project, and this project has never given a problem building and pushing to nuget and GPR. I suspect that the issue is introduced when publishing a multi-target nuget package (I have no clue what could possibly cause this).

I’ll keep you up-to-date if using nuget.exe works consistently.

(6/6 successful pushes)

The chance of a dotnet nuget push failing seems to increase with the size of the package (but it’s still somewhat random).

Here is an example that shows pushes of various sized packages:

By the time we get to a 2049 kB package, the push is almost certain to fail!

Interesting finding. I never had a problem pushing a .NET Standard nuget package to github.com/nuget.org. The problem started occuring by creating a multi-target nuget package. This implies that for each target, there’s a DLL in the package and increases the size of the package drastically.

But how come the package can successfully be pushed to nuget.org all the time, while it fails for github.com, using the same command?

Anyhow, using nuget.exe seems to work reliably. Thanks for the help.

It’s probably something to do with GitHub’s load balancer and they way chunked encoding works. The team will hopefully be digging into it soon!

This definitely has something to do with the size of the package. I have smaller packages that upload without issue but bigger ones fail with the above error message. It’s really really inconvenient and frustrating.

1 Like

I’ve written a GitHub Action based on https://github.com/jcansdale/gpr that you should find works consistently.

You can use it like this:

    - uses: jcansdale/gpr@v0.1.257
      with:
        command: push
        path: **/*.nupkg

Please let me know if you try it!

Great! Thanks. I’ll check this out.

Hi, thanks for this Github Action. Just note that if you build a dotnet package whit --include-symbols then it will upload each package two times and complain that its allready uploaded second time it gets uploaded.

1 Like

I replaced dotnet nuget by @jcansdale tool for working with the GitHub Package Registry and it works like a charm:

      - name: Install tool for working with the GPR
        run: dotnet tool install -g gpr

      - name: Publish Package
        run: |
          gpr push PATH-TO-PKG-FILE.nupkg

Hello, we are seeing this issue with Nuget packages < 50 KB in size. It would be nice to avoid having to use the gpr push workaround. Do we know what the root cause for this failure is when using dotnet nuget push? There are no commas in my package description.