Skip to content

Referencing ${self:} leads to crash in the print command #4556

Closed

Description

@HyperBrain

This is a Bug Report

Description

When referencing ${self:} with the new circular variables support, the print command will crash with a stack overflow. (For details see #4144 (review) and the discussion in the PR).

This is due to a missing circular object support in the modules to traverse the service object tree used by the print command.

Additional Data

Activity

  1. HyperBrain commented on Dec 11, 2017

    @HyperBrain
    ContributorAuthor

    /cc @horike37 @erikerikson @pmuens
    This is the decoupled bug for the print command

  2. erikerikson commented on Dec 13, 2017

    @erikerikson
    Contributor

    Update:
    js-yaml doesn’t and will not support cyclic objects. I opened nodeca/js-yaml#387 and was advised that as callers we have the responsibility to sanitize the input.

  3. HyperBrain commented on Dec 14, 2017

    @HyperBrain
    ContributorAuthor

    Thanks for the update 💯
    So we should probably go for a different module that supports cyclic objects instead of js-yaml.

  4. erikerikson commented on Dec 14, 2017

    @erikerikson
    Contributor

    Oops. Just seeing that comment. I suppose we could but I've submitted a change that would solve this issue.

    There was the issue of cycles but there was also the issue that self-references pulled in the original "augmented" service (via the cache) as opposed to the stripped down service being explicitly loaded in the print command. See print.js, lines 38 & 39 for the remediation.

  5. erikerikson commented on Dec 14, 2017

    @erikerikson
    Contributor

    In implementing a fix, I first tried re-using the already populated service (it was hanging off of this.serverless) but found that version of the service was all sorts of augmented. My initial attempts to reverse that were...

        // remove framework additions
        delete this.serverless.service.package;
        delete this.serverless.service.serverless;
        delete this.serverless.service.serviceObject;
    

    ...but there were other additions (e.g. on this.serverless.service.provider) and it struck me there was a general issue and that this is why the existing implementation was chosen (to avoid the whack-a-mole and update print command liability re-using the populated service represents).

    The counter to that perspective is that as implemented there is a risk that we miss changes in the standard path... it's a dilemma. However, there is a nuanced to solve problem of identifying what was an addition and what was already present in the service. Additionally perhaps a "what wasn't in the service but is now and we want to show it" problem.

  6. added a commit that references this issue on Dec 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions