Skip to content

All variables should resolve, timeout, or be identified #4687

Closed

Description

@erikerikson

This is a Bug Report

It is possible to define a project that never resolves variable population.

Description

  • What went wrong?
    I attempted to package a project. SLS loaded and then hung indefinitely.

  • What did you expect should have happened?
    I expected a package to be produced

  • What was the config you used?
    Simple config:
    serverless.yml:

service: test
provider:
  name: aws
custom:
  project: ${file(./project.yml)}

project.yml:

foo: baz
bar:
  name: ${self:custom.project.foo}
  • What stacktrace or error message from your provider did you see?
    none is given

Additional Data

I've instrumented the code and produced the following list of unresolved variable resolutions:

unsettled promises:
file(./project.yml) waited on by:
${file(./project.yml)}
${file(./project.yml)}

self:custom.project.foo waited on by:
${self:custom.project.foo}

The problem is that resolving ${file(./project.yml)} involves, prior to replacing the custom.project attribute on the service object, attempting to resolve ${self:custom.project.foo} which then circularly attempts to resolve ${file(./project.yml)} again, resulting in a deadlock since ${file(./project.yml)} now cannot resolve until ${file(./project.yml)} is resolved.

It could have been any asynchronously resolving variable that referred to itself prior to being replaced in the origin object.

  • Serverless Framework Version you're using: 1.25.0 / master
  • Operating System: osx
  • Stack Trace: n/a
  • Provider Error messages: n/a

Activity

  1. changed the title [-]Never resolving variables[/-] [+]All variables should resolve or be identified as failing to resolve[/+] on Jan 27, 2018
  2. changed the title [-]All variables should resolve or be identified as failing to resolve[/-] [+]All variables should resolve, timeout, or be identified[/+] on Jan 27, 2018
  3. added a commit that references this issue on Feb 20, 2018
  4. added this to the 1.27 milestone on Feb 24, 2018
  5. bsdkurt commented on Mar 4, 2018

    @bsdkurt
    Contributor

    Can this be reopened? I found case where the recursion does not go far enough. The following serverless.yml fails:

    service: test
    
    custom: ${file(custom-properties-${opt:stage, self:provider.stage}.yml)}
    
    provider:
      name: aws
      region: ${self:custom.region}
    
      environment:
        TEST: ${cf:resources-v1-dev.UserPoolArn}

    with the following error

      Serverless Error ---------------------------------------
     
      Inaccessible host: `cloudformation.'. This service may not be available in the `${deep:1.region}' region.
    
  6. erikerikson commented on Mar 4, 2018

    @erikerikson
    ContributorAuthor

    @bsdkurt Thanks for reporting this and offering a change too!

  7. bsdkurt commented on Mar 4, 2018

    @bsdkurt
    Contributor

    @erikerikson Your welcome. One thing I wasn't able to determine is that by allowing root recursion to continue, did I introduce infinite recursion if there is a env var loop? If I did, then I would suggest instead of a boolean for root, rename root to depth and make it an integer for max depth. e.g. allow recursion say 10 depth and then error out if not resolved.

  8. erikerikson commented on Mar 4, 2018

    @erikerikson
    ContributorAuthor

    It is possible to "infinitely" recurse if someone introduced an explicit ungroundable cycle in their references. The behavior of the framework, prior to any of these changes, was to recurse until the stack became too deep and was rejected by the VM. This results in a crash and that seemed appropriate enough behavior. I think now it will deadlock and report the offending (pending) variables. I'd certainly suggest that 10 would be far too low a number given the number of generations that some of these evaluations go through (particularly on complex services).

    That said some sort of safety mechanism that would give users a more legible error or statement of the conditions would be helpful. I suppose it would be best to come up with a service that reproduces the case before fixing the matter however.

  9. HyperBrain commented on Mar 5, 2018

    @HyperBrain
    Contributor

    @erikerikson @bsdkurt Please keep me updated on the discussion and the state of any additional PRs. I'll take care of merging then.

  10. erikerikson commented on Mar 5, 2018

    @erikerikson
    ContributorAuthor

    I've offered a test on #4800. I think after it is included, #4800 should be GTM.

  11. added a commit that references this issue on Mar 6, 2018
  12. apsoto commented on Jun 2, 2020

    @apsoto
    Contributor

    I've noticed that if you mistakenly have a variable reference itself it gets stuck in what appears to be an infinite loop. I've waited many minutes, and the deploy process provides no feedback nor does it error out.

    An example I mistakenly did due to a bad cut and paste in my serverless.yml:

    provider:
      environment:
        SOME_VARIABLE: ${self:provider.environment.SOME_VARIABLE}
    
  13. erikerikson commented on Jun 2, 2020

    @erikerikson
    ContributorAuthor

    Interesting @aposto. I would expect that to be the case and there isn't logic to detect it. I'd guess that's worthy of an issue if you're willing to open one up?

    Under the covers it will be waiting on its own promise, an obvious deadlock. Sorry about the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions