zola icon indicating copy to clipboard operation
zola copied to clipboard

Stack overflow when blog count is too high

Open kcrazy opened this issue 8 months ago • 10 comments

Bug Report

Environment

Windows 11 22H2

Zola version: 827655181113eb634275c6d7928621d885e13918

Expected Behavior

OK

Current Behavior

zola.exe serve
Building site...
Checking all internal links with anchors.
> Successfully checked 0 internal link(s) with anchors.
-> Creating 5615 pages (0 orphan) and 1 sections

thread 'main' has overflowed its stack

Call stack:

.....
core::ops::function::FnOnce::call_once::h2c917d912396d3d6 0x00007ff7836fa436
std::sys_common::backtrace::__rust_begin_short_backtrace::h29c25537c4ca3834 0x00007ff783712d09
std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h300e1a97ad7cdd03 0x00007ff78379c7cc
[inline] std::rt::lang_start_internal::closure$2() rt.rs:148
[inline] std::panicking::try::do_call() panicking.rs:504
[inline] std::panicking::try() panicking.rs:468
[inline] std::panic::catch_unwind() panic.rs:142
std::rt::lang_start_internal() rt.rs:148
std::rt::lang_start::h13c5bcd20128510d 0x00007ff78379c7a7
main 0x00007ff783710889
[inline] invoke_main() 0x00007ff7852e8ab0
__scrt_common_main_seh() 0x00007ff7852e8a8e
<unknown> 0x00007ffea666257d
<unknown> 0x00007ffea836aa58

callstack.txt

Step to reproduce

  1. Create a Zola site with 5615 blogs.
  2. Run the zola.exe serve command.

kcrazy avatar Dec 17 '23 13:12 kcrazy

~/C/z/c/s/b/extra-huge-blog (next|✔) $ zola build
Building site...
Checking all internal links with anchors.
> Successfully checked 0 internal link(s) with anchors.
-> Creating 100000 pages (0 orphan) and 0 sections
Done in 31.4s.

Can you share the site? I don't have that issue

Keats avatar Dec 17 '23 20:12 Keats

Sorry, this issue is not related to the number of blogs.

through my debugging, I've found that the reason is

my config.toml:

# default_language = "en." ## <==== I haven't configured the 'default_language' setting
build_search_index = true

This causes a crash for my Chinese articles within the 'build_index' function in 'components\search\src\lib.rs' when using 'index.to_json().'

components\search\src\lib.rs -> build_index:

pub fn build_index(lang: &str, library: &Library, config: &Config) -> Result<String> {
    // <=== lang is "en"
    let language = match lang::from_code(lang) {
        Some(l) => l,
        None => {
            bail!("Tried to build search index for language {} which is not supported", lang);
        }
    };
    let language_options = &config.languages[lang];
    let mut index = IndexBuilder::with_language(language);
    index = build_fields(&language_options.search, index);
    let mut index = index.build();

    for (_, section) in &library.sections {
        if section.lang == lang {
            add_section_to_index(&mut index, section, library, &language_options.search);
        }
    }

    Ok(index.to_json()) // <==== crash
}

kcrazy avatar Dec 18 '23 13:12 kcrazy

ah yes that's known. Do you have huge code blocks or very long strings by any chance?

Keats avatar Dec 18 '23 13:12 Keats

I tried to condense my article to pinpoint where the issue might lie, but it seems the problem only arises when the entire article is put together.

I noticed:

components\libs\Cargo.toml:

[dependencies]
elasticlunr-rs = { version = "3.0.0", features = ["da", "no", "de", "du", "es", "fi", "fr", "it", "pt", "ro", "ru", "sv", "tr"] }

It seems that the features list doesn't include Chinese. I'm not sure if it's possible to add that. Thank you.

kcrazy avatar Dec 18 '23 13:12 kcrazy

You need to do a custom build to include Chinese/Japanese: https://github.com/getzola/zola/blob/master/Cargo.toml#L54-L55 since they can bloat the binary quite a bit.

Can you try the next branch to see if it still errors?

Keats avatar Dec 18 '23 13:12 Keats

The error still persists in the next branch. 47a862f21f1f6eefe8eb579d245601f21301c68b

kcrazy avatar Dec 18 '23 14:12 kcrazy

Is the repo public? I've seen that happen with search index generation before on some huge content. Is the content in chinese?

Keats avatar Dec 18 '23 14:12 Keats

i created a private repo here zola_blog

kcrazy avatar Dec 18 '23 16:12 kcrazy

Hm that works for me on mac?

Keats avatar Dec 18 '23 16:12 Keats

I don't have a Mac, I've only tried it on Windows.

kcrazy avatar Dec 19 '23 01:12 kcrazy