Shortcode content loop hugo does not finish building the site

Hi all,

I’ve got this warning when I build my site on my server:

WARN 2018/06/25 15:49:07 WARNING: Timed out creating content for page
"post/blumen-parade/" (.Content will be empty). This is most
likely a circular shortcode content loop that should be fixed. If this
is just a shortcode calling a slow remote service, try to set
"timeout=20000" (or higher, value is in milliseconds) in config.toml.

The build is not finished.

Setting timeout=20000 has no effect.

I don’t get the warning on my local desktop. The site is built without problems locally.

When I don’t use this shortcode, the warning disappears and the site is built slowly but successfully. So maybe this is the offending shortcode the warning hints to.

<h2 class="f3 fw4 pa3 mv0">{{ with .Get "title" }}{{.}}{{ end }}</h2>
<div class="cf pa2">
{{ $matchstr := (.Get "src" ) }}
{{ range .Page.Resources.Match $matchstr }}
{{ $scaled := .Fill "362x362 smart" }}
{{ $unscaled := .Resize "1200x Gaussian" }}
<div class="fl w-50 w-25-m w-20-l pa2">
<a href="{{ $unscaled.RelPermalink }}" class="db link dim tc">
  <img src="{{ $scaled.RelPermalink }}" alt="" title="" class="w-100 db outline black-10">
{{ end }}

The shortcode is called like this:

{{< gallery src="IMG_*" title="Blumenparade" >}}

The images are ressources in the folder of the content. They all have names like “IMG_20160630_203432.jpg”

The shortcode didn’t cause problems until I changed the design of the site. I was using it to make an album from the images in the content folder for quite some time.

I tried to build the site with different versions of hugo: from 0.39 to current.

I am working in a shared webspace, so there are other users on the machine using memory and cpu. I see with top that hugo uses the cpu heavily for some seconds and then disappears from the top screen. I can see the process with ps.

The warning is quite clear. Can’t I loop through files in a folder in the way I do? I don’t see the error. Please open my eyes.

And if the shortcode is ok. How can I debug the problem?


There has been one similar report from a user. I have not been able to reproduce it, yet.

However, looking at the above:

  • If there problem is image processing on your remote host, I would recommend that you commit your “resources/_gen” folder with the processed images to Git and use that when you build from your shared host.

Doing so the site was built without problems.

So maybe the image processing on the server does not work always.

If I can do anything to debug the problem please let me know.

If this is on a *nix box, it would be good if you could do

kill -SIGABRT [pid]

On the “stuck process”, and post the big stack trace here.

I am getting the same error on a specific page in my site. However, in my case the site finishes rendering, hugo doesn’t hang… only that particular page is empty.

I can’t find out what the shortcode loop could be… if you can help me with this I would appreciate it.

The site is at , master branch.
The page with the error is user/Introduction/User

I get the error on my local, which is hugo 0.47.1, but not on the production site which is on Netlify, using version 0.37. :thinking:

A “shortcode loop” sounds like a shortcode calling itself, like a function calling itself in a computer program. That could lead to the shortcode never finishing building itself, since it keeps starting over every time it calls itself. Could someone confirm this?

The only shortcode I am using there is {{% notice %}} which comes with my theme. It is extensively used with no problems in dozens of pages that are working fine.

I looked for issues related to that shortcode (like mismatched start/end tags) but couldn’t find any. Also, the fact that this works in one place/version but not in the other, makes me suspect a bug…

The only thing I find suspicious in that file is that :btn: btn stuff in the beginning. Could that generate a shortcode loop message?

In this particular case it is the shortcode biting its tail by accessing its own .Content (or some of the content related variabled, .ReadingTime etc.).

In Hugo, we have made these variables unavailable from .Page in a shortcode, but you can typically do this from a shortcode:

{{ range .Site.Pages }}
{{ .Content }}
{{ end 

The above cannot possibly work from a shortcode. You can show other pages’ content, but not the branch you are sitting on. But note that Hugo will finish building in the above case (we have timeout to bail out of the impossible situation above).

Note that regular page metadata (.Date, .Title etc.) is fine in all cases.

I found my own gallery solution with fancybox.
I moved the pictures to folder gallery and changed the procedure to page bundles.
Hope this can help to get a working solution - you have to adopt it!

<div class="row">
{{range .Resources -}}{{ $original := . }}{{ $.Scratch.Set "image" ($original.Fit "370x370") }}{{ $image := $.Scratch.Get "image" }}
	<a href="{{.Name}}" class="fancybox" ><img src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{.Name}}" /></a> 
{{- end}}

@bep I just spent a couple of hours debugging why one my files was giving that timeout error. I am not using any shortcodes except a few notices that don’t depend on any other shortcodes or collections. So I really wasn’t seeing how there could be a loop here.

It finally occurred to me to test breaking the file down to parts. If I cut the first half of content, the error went away. If I cut the second part, the error went away. I ended up increasing the timeout and my content gets created just fine.

Note that I am using Asciidoc and I am stuck with the horrendous Ruby execution times. So a single file seems to be taking more than 10s to render! No loops, no “calling a slow remote service”, just plain old slooooooow eeexeeeecuuuutiiiiooooooon.

So I guess the error message text feels a bit treacherous, since it sent me chasing shortcode loops in a long, long file that I hadn’t written (in Russian - to make things worse).

I don’t suppose Hugo can distinguish the time spent in Hugo code from the time spent in the external content handlers? So that time wouldn’t count for the timeout.

No. But we could possibly increase the default timeout value. The important part of that is to avoid “hanging application”.

Ok, maybe also improve the text of the error message, perhaps add something about big files with slooow renderers… :slight_smile:

I have a shortcode which leads to the above-mentioned error. The goal is to show a list of related pages. Any hints on how to fix it?

{{- $cta := .Inner | default "See also:" -}}
{{- with (where (where ($.Site.RegularPages.Related .Page) ".Draft" "==" false) ".Params.hidden" "!=" true) | first 5 -}}
<section class="related">
    <h3>{{ $cta }}</h3>
        {{- range . }}
        <li><a href="{{ .Permalink }}">{{ .Title }}</a> <span class="muted">({{ .ReadingTime }} min)</span></li>
        {{- end }}
{{- end }}

I am far from being knowledgeable in Hugo, but as a general developer tip, why that where inside where? You can make it a single where with a double condition.

You have and and or available as functions so you can combine multiple conditions, if I am not mistaken.

A where clause is different than a typical condition, it filters page collections according to a set of criteria’s which are not infinite.

So where clause in where clause is how you double a where clause.

See nested where clauses

I should edit my post and leave only the part that is factual:

:slight_smile: thanks Regis for correcting me!

1 Like

Thanks for this post! I just ran into the same issue: My site did build well on my local machine but not on the build-server. Raising the timeout from 10s to 20s fixed it.