question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using `key this`, `observer this`, `signatory this` in template-local let clause causes infinite loop.

See original GitHub issue

I confirm that, if this is a bug that has security implications, I already contacted security@digitalasset.com and followed the responsible disclosure policy.

I confirm that this is not a question or a request for technical support by the community, for which the Daml forum is available.

Affected Daml version

2.0.0

Bug description

Using the expression key this in a template-local let clause seems to cause some sort of infinite recursion.

To reproduce

  1. Create a daml project with the below Main module.
  2. Open the Script view of the script.
  3. Enjoy the sound of your laptop fans spinning as the scenario service maxes all your CPUs.
  4. Wait patiently for the message "Scenario service backend error: BErrorClient (ClientIOError (GRPCIOBadStatusCode StatusDeadlineExceeded (StatusDetails {unStatusDetails = \"Deadline Exceeded\"})))" appears
module Main where

import Daml.Script

template T
  with
    p : Party
  where
    signatory p
    key p : Party
    maintainer key

    let k = key this

t = script do
  p <- allocateParty "p"

  submit p do
  createCmd T with p

Expected behavior

The same thing as if the let clause read let k = p. Ie the script view appears.

Additional context

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:21 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
sofiafaro-dacommented, Apr 7, 2022

We are not adding warnings for everything that could loop infinitely – this is not possible in theory nor in practice.

I think it’s pretty clear that this is an infinite loop:

template T
  with ...
  where
    signatory (signatory this)

And this is an infinite loop that doesn’t look like it:

template T
  with ...
  where
    signatory x
    let foo = signatory this

Unfortunately adding a warning in the latter case is difficult, even for a basic thing like detecting key this and signatory this, and is at best an approximation.

I agree with @akrmn (and others in the language team) that the problem here is the template local let syntax, since it creates a false impression of the semantics. I’m in favor of deprecating it and encouraging people to write global functions instead, where the flow of computation is much more explicit.

1reaction
stefanobaghino-dacommented, May 16, 2022

OK, I would not try to fix the semantics. Furthermore, lazy semantics only here seems confusing.

I would say to move on with “better error message at runtime and clear documentation of the semantics” to be acceptance criteria to consider this closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

infinite loop caused by `isInViewRef` · Issue #572 - GitHub
When calling setRef from this package, it causes an infinite loop if called from ... Callback from IntersectionObserver with a new state.
Read more >
MutationObserver create infinite loop when I replace a string ...
The infinite loop is caused by replacing typed / characters with <span>/</span> without turning off the observer first - each replacement ...
Read more >
How to solve the React useEffect Hook's infinite loop patterns
Solve the issue of infinite loops when using the useEffect Hook in React to more smoothly utilize the Hook for your app's side...
Read more >
Chapter 5 | Python For Everyone | Trinket
If there is no iteration variable, the loop will repeat forever, resulting in an infinite loop. Infinite loops. An endless source of amusement...
Read more >
5 useEffect Infinite Loop Patterns | by Naveen DA
In general, infinite loops are considered bad practices. But in some edge cases, you don't have any choice to choose rather than an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found