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

actions: crash if action yaml cannot be parsed #23658

Closed
krombel opened this issue Mar 23, 2023 · 7 comments · Fixed by #23972
Closed

actions: crash if action yaml cannot be parsed #23658

krombel opened this issue Mar 23, 2023 · 7 comments · Fixed by #23972
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Milestone

Comments

@krombel
Copy link

krombel commented Mar 23, 2023

Description

When there is an error with the yaml syntax gitea crashes

Gitea Version

1.19.0

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

2023/03/22 15:07:24 [641b19ac-8] router: completed POST /api/internal/ssh/1/update/8 for 172.19.0.1:0, 200 OK in 2.6ms @ private/key.go:17(private.UpdatePublicKeyInRepo)
Received disconnect from 172.19.0.1 port 49392:11: disconnected by user
Disconnected from user git 172.19.0.1 port 49392
2023/03/22 15:07:25 ...les/cache/context.go:62:GetContextData() [W] [641b19ad] cannot get cache context when getting data: &{context.Background.WithCancel.WithCancel.WithValue(type pprof.labelContextKey, val {"graceful-lifecycle":"with-hammer"}) 0xc005052a00 false}
2023/03/22 15:07:25 ...les/cache/context.go:71:SetContextData() [W] [641b19ad] cannot get cache context when setting data: &{context.Background.WithCancel.WithCancel.WithValue(type pprof.labelContextKey, val {"graceful-lifecycle":"with-hammer"}) 0xc005052a00 false}
2023/03/22 15:07:25 ...les/cache/context.go:62:GetContextData() [W] cannot get cache context when getting data: &{context.Background.WithCancel.WithCancel.WithValue(type pprof.labelContextKey, val {"graceful-lifecycle":"with-hammer"}) 0xc005052a00 false}
2023/03/22 15:07:25 ...les/cache/context.go:71:SetContextData() [W] cannot get cache context when setting data: &{context.Background.WithCancel.WithCancel.WithValue(type pprof.labelContextKey, val {"graceful-lifecycle":"with-hammer"}) 0xc005052a00 false}
2023/03/22 15:07:25 ...les/cache/context.go:62:GetContextData() [W] cannot get cache context when getting data: *db.Context.WithValue(type struct {}, val NotifyPushCommits)
2023/03/22 15:07:25 ...les/cache/context.go:71:SetContextData() [W] cannot get cache context when setting data: *db.Context.WithValue(type struct {}, val NotifyPushCommits)
2023/03/22 15:07:25 ...les/cache/context.go:62:GetContextData() [W] cannot get cache context when getting data: *db.Context.WithValue(type struct {}, val NotifyPushCommits)
2023/03/22 15:07:25 ...les/cache/context.go:71:SetContextData() [W] cannot get cache context when setting data: *db.Context.WithValue(type struct {}, val NotifyPushCommits)
time="2023-03-22T15:07:25Z" level=fatal msg="yaml: unmarshal errors:\n  line 210: cannot unmarshal !!str `${{ fro...` into []interface {}"
Received signal 15; terminating.

Git Version

No response

Operating System

No response

How are you running Gitea?

docker

Database

None

@lunny
Copy link
Member

lunny commented Mar 23, 2023

Could you provide the yaml file here?

@ghnp5
Copy link

ghnp5 commented Mar 25, 2023

Yeah, I was going to report exactly this!

@lunny - I got this:

time="2023-03-25T15:22:18Z" level=fatal msg="yaml: unmarshal errors:\n line 61: cannot unmarshal !!str ${{ fro... into []interface {}"
Received signal 15; terminating.

I was wondering why the Action didn't trigger. No logs anywhere, but then I found it in the Gitea docker logs.

In my case, I'm doing this (minimal example):

jobs:
  c_set_matrix:
    name: Set Matrix
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set_matrix.outputs.domains }}
    steps:
      - name: Set Matrix
        id: set_matrix
        run: |
          echo "domains=[...]" >> $GITHUB_OUTPUT

  d_deploy:
    name: Deploy
    runs-on: ubuntu-latest
    needs: c_set_matrix
    strategy:
      matrix:
        stage:
          - server1
          - server2
          - server3
          - server4
        domain: ${{ fromJSON(needs.c_set_matrix.outputs.matrix) }}
    steps:
      - ...

So, two issues I see here:

  1. Gitea is completely crashing if there is a syntax error in a workflow

  2. fromJSON() should work (but could well be my fault, as I never worked with GitHub Actions before), as per https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object

@lunny
Copy link
Member

lunny commented Mar 26, 2023

I cannot reproduce the crash in my local machine with 1.19 or main branch with your above content as a workflow file.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 26, 2023

I guess the author means that the act runner crashes.

The log is: time="2023-03-25T15:22:18Z" level=fatal msg="yaml: unmarshal errors:\n line 61: cannot unmarshal !!str ${{ fro... into []interface {}" , it comes from the runner?

Hmm ... it seems that I misunderstood. Author meant that "Gitea is completely crashing"

@wxiaoguang
Copy link
Contributor

OK, I know the problem now.

The problem is that a lot of code in act package uses log.Fatal

You can even reproduce the crash with a very simple YAML.

To fix the problem .... replace all log.Fatal with return err

func TestActCrash(t *testing.T) {
	workflow, err := model.ReadWorkflow(bytes.NewReader([]byte(`
name: checks
on:
  - asfd:
    - a
`)))
	assert.NoError(t, err)
	workflow.On()
	t.Log("Succeeded")
}

Then

=== RUN   TestActCrash
time="2023-03-26T23:02:28+08:00" level=fatal msg="yaml: unmarshal errors:\n  line 4: cannot unmarshal !!map into string"

@ghnp5
Copy link

ghnp5 commented Mar 26, 2023

Hey

Yeah, I meant the Gitea docker container, not the "act_runner" daemon.

Great if you were able to find the reason for the crash!

Thanks!

@lunny lunny added this to the 1.19.1 milestone Mar 26, 2023
@wolfogre wolfogre added the topic/gitea-actions related to the actions of Gitea label Mar 27, 2023
@wolfogre
Copy link
Member

I am tring to fix it on nektos/act#1705

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants