# Stackoverflow error with no stacktrace

**URL:** https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690
**Category:** General Usage
**Tags:** exception, forwarddiff, stackoverflow, stacktrace
**Created:** [November 2, 2023, 11:17am UTC](https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690 "2023-11-02T11:17:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)
#### Post date: [November 2, 2023, 11:17am UTC](https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690/1 "2023-11-02T11:17:19Z")

</div>

I’m experienceing a strange bug which results in a stack overflow error with no stacktrace at all. I’m not sure how or why this happens, and I have found it impossible to diagnose. I haven’t been able to reprodruce the bug with a minimized example… 😕

Has anyone experienced anything similar? Is there a way to recover the stacktrace (from the most recent exception) to look for clues?

---

<div class="post-metadata">

### Author: ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)
#### Post date: [November 2, 2023, 11:47am UTC](https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690/2 "2023-11-02T11:47:15Z")

</div>

Update.

I’ve narrowed down the error slightly. It appears with the following line

```julia
diffcfg = ForwardDiff.GradientConfig(f, θ, ForwardDiff.Chunk{length(θ)}())
ForwardDiff.gradient!(diffresult, f, θ, diffcfg, Val{true}())

```

But not when I remove my diffcfg.

```julia
ForwardDiff.gradient!(diffresult, f, θ)

```

Going to dig further, leaving this trail of breadcrumbs incase anyone else faces a similar issue

---

<div class="post-metadata">

### Author: ![Larbino1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/larbino1/32/37831_2.png) [@Larbino1](https://discourse.julialang.org/u/Larbino1)
#### Post date: [November 2, 2023, 11:59am UTC](https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690/3 "2023-11-02T11:59:12Z")

</div>

Replacing

```julia
# OLD, wrong
ForwardDiff.Chunk{length(θ)}()

# NEW, good
ForwardDiff.Chunk(θ)

```

I think this results in a different chunk size being chosen (12 is the default threshold) instead of 22. I’m done for now, not sure how the previous case caused stack overflow, or why it should do so WITHOUT showing a stacktrace.

For reference, here is the `Chunk` function from ForwardDiff

```julia
function Chunk(input_length::Integer, threshold::Integer = DEFAULT_CHUNK_THRESHOLD)
    N = pickchunksize(input_length, threshold)
    0 < N <= DEFAULT_CHUNK_THRESHOLD && return CHUNKS[N]
    return Chunk{N}()
end

```

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [November 2, 2023, 1:21pm UTC](https://discourse.julialang.org/t/stackoverflow-error-with-no-stacktrace/105690/4 "2023-11-02T13:21:00Z")

</div>

Try using the ‘err’ global, if you’re running on the REPL? The most recent exception should go there.
