Bug 156677 - spreadsheet which asserts on data, recalculate, recalculate hard
Summary: spreadsheet which asserts on data, recalculate, recalculate hard
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
24.2.0.0 alpha0+
Hardware: All Linux (All)
: medium normal
Assignee: Caolán McNamara
URL:
Whiteboard: target:24.2.0
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-08 15:54 UTC by Caolán McNamara
Modified: 2023-08-14 13:56 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
fairly small example I can reproduce this with (12.30 KB, application/vnd.oasis.opendocument.spreadsheet)
2023-08-08 15:55 UTC, Caolán McNamara
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Caolán McNamara 2023-08-08 15:54:42 UTC
Description:
This is related to threaded calculations, and the current largest block of known crashtesting failures

Steps to Reproduce:
1. load attached ods in a dbgutil version
2. after load, data, recalculate, recalculate hard

Actual Results:
#0  0x00007ffff78b0844 in __pthread_kill_implementation () at /lib64/libc.so.6
#1  0x00007ffff785fabe in raise () at /lib64/libc.so.6
#2  0x00007ffff784887f in abort () at /lib64/libc.so.6
#3  0x00007ffff784879b in _nl_load_domain.cold () at /lib64/libc.so.6
#4  0x00007ffff7858147 in  () at /lib64/libc.so.6
#5  0x00007fff9a6d587e in ScFormulaCell::MaybeInterpret() (this=0x1e547f0) at sc/inc/formulacell.hxx:467
#6  0x00007fff9aaf6c79 in ScFormulaCell::IsValue() (this=0x1e547f0) at /home/caolan/LibreOffice/core/sc/source/core/data/formulacell.cxx:2760
#7  0x00007fff9aeaef26 in ScInterpreter::IterateParametersIfs(double (*)(sc::ParamIfsResult const&))
    (this=0xb0cd800, ResultFunc=0x7fff9aec4d00 <ScInterpreter::ScCountIfs()::$_0::__invoke(sc::ParamIfsResult const&)>)
    at /home/caolan/LibreOffice/core/sc/source/core/tool/interpr1.cxx:6000
#8  0x00007fff9aeb2e23 in ScInterpreter::ScCountIfs() (this=0xb0cd800) at /home/caolan/LibreOffice/core/sc/source/core/tool/interpr1.cxx:6683
#9  0x00007fff9af3518c in ScInterpreter::Interpret() (this=0xb0cd800) at /home/caolan/LibreOffice/core/sc/source/core/tool/interpr4.cxx:4306
#10 0x00007fff9aaf361a in ScFormulaCell::InterpretTail(ScInterpreterContext&, ScFormulaCell::ScInterpretTailParameter)
    (this=0x1df6910, rContext=..., eTailParam=ScFormulaCell::SCITP_NORMAL) at /home/caolan/LibreOffice/core/sc/source/core/data/formulacell.cxx:1946
#11 0x00007fff9a6758e2 in ScColumn::CalculateInThread(ScInterpreterContext&, int, unsigned long, unsigned long, unsigned int, unsigned int)
    (this=0x183a9f0, rContext=..., nRow=1, nLen=4, nOffset=0, nThisThread=0, nThreadsTotal=20) at /home/caolan/LibreOffice/core/sc/source/core/data/column2.cxx:3256
#12 0x00007fff9ac448c2 in ScTable::CalculateInColumnInThread(ScInterpreterContext&, short, short, int, int, unsigned int, unsigned int)
    (this=0x1d0c210, rContext=..., nColStart=1, nColEnd=1, nRowStart=1, nRowEnd=4, nThisThread=0, nThreadsTotal=20)
    at /home/caolan/LibreOffice/core/sc/source/core/data/table1.cxx:2654
#13 0x00007fff9a84ea03 in ScDocument::CalculateInColumnInThread(ScInterpreterContext&, ScRange const&, unsigned int, unsigned int)
    (this=0x1be4b60, rContext=..., rCalcRange=..., nThisThread=0, nThreadsTotal=20) at /home/caolan/LibreOffice/core/sc/source/core/data/documen8.cxx:420
#14 0x00007fff9ab07e53 in ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope&, bool&, bool&, int, int)::Executor::doWork() (this=0xb22e6b0)
    at /home/caolan/LibreOffice/core/sc/source/core/data/formulacell.cxx:4877
#15 0x00007ffff66a351e in comphelper::ThreadTask::exec() (this=0xb22e6b0) at /home/caolan/LibreOffice/core/comphelper/source/misc/threadpool.cxx:319
#16 0x00007ffff66a714f in comphelper::ThreadPool::ThreadWorker::execute() (this=0x31af3d0) at /home/caolan/LibreOffice/core/comphelper/source/misc/threadpool.cxx:85
#17 0x00007ffff7ce190c in salhelper::Thread::run() (this=0x31af3d0) at /home/caolan/LibreOffice/core/salhelper/source/thread.cxx:39
#18 0x00007ffff7ce214e in threadFunc(void*) (param=0x31af3e0) at include/osl/thread.hxx:189
#19 0x00007ffff7f51efd in osl_thread_start_Impl(void*) (pData=0x31b14c0) at /home/caolan/LibreOffice/core/sal/osl/unx/thread.cxx:239
#20 0x00007ffff78ae907 in start_thread () at /lib64/libc.so.6
#21 0x00007ffff7934870 in clone3 () at /lib64/libc.so.6


Expected Results:
no assert


Reproducible: Always


User Profile Reset: No

Additional Info:
load document ~/Downloads/forum-mso-en4-784502.xlsx

after it has loaded:

(gdb) break column4.cxx:1946
(gdb) break column4.cxx:1966

data, recalculate, recalculate hard,

the first time breakpoint #1 gets hit:

at column4.cxx:1946 NeedsInterpret is true, so cell 
{nRow = 1, nCol = 0, nTab = 3 } was dirty and is set
not-dirty by Interpret. mxGroup->mbPartOfCycle is false
so this returns successfully to allow threading.

the bt to there was:

#0  lcl_EvalDirty(mdds::mtv::soa::multi_type_vector<sc::CellStoreTraits>&, int, int, ScDocument&, boost::intrusive_ptr<ScFormulaCellGroup> const&, bool, bool, bool&, bool&)
    (rCells=..., nRow1=1, nRow2=4, rDoc=..., mxGroup=..., bThreadingDepEval=true, bSkipRunning=false, bIsDirty=@0x7fffffff4a16: true, bAllowThreading=@0x7fffffff4a17: true)
    at sc/source/core/data/column4.cxx:1963
#1  0x00007fff9eef70d1 in ScColumn::HandleRefArrayForParallelism(int, int, boost::intrusive_ptr<ScFormulaCellGroup> const&) (this=0x15ee480, nRow1=1, nRow2=4, mxGroup=...)
    at sc/source/core/data/column4.cxx:2012
#2  0x00007fff9f44448a in ScTable::HandleRefArrayForParallelism(short, int, int, boost::intrusive_ptr<ScFormulaCellGroup> const&)
    (this=0x1eebda0, nCol=0, nRow1=1, nRow2=4, mxGroup=...) at sc/source/core/data/table1.cxx:2567
#3  0x00007fff9f06b691 in ScDocument::HandleRefArrayForParallelism(ScAddress const&, int, boost::intrusive_ptr<ScFormulaCellGroup> const&)
    (this=0x1ba9a40, rPos=..., nLength=4, mxGroup=...) at sc/source/core/data/document.cxx:1792
#4  0x00007fff9f3018f7 in (anonymous namespace)::ScDependantsCalculator::DoIt() (this=0x7fffffff4eb8) at sc/source/core/data/formulacell.cxx:4585
#5  0x00007fff9f30085a in ScFormulaCell::CheckComputeDependencies(sc::FormulaLogger::GroupScope&, bool, int, int, bool)
    (this=0x2142cf0, rScope=..., fromFirstRow=false, nStartOffset=0, nEndOffset=3, bCalcDependencyOnly=false) at sc/source/core/data/formulacell.cxx:4720
#6  0x00007fff9f2ff392 in ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope&, bool&, bool&, int, int)
    (this=0x2142cf0, aScope=..., bDependencyComputed=@0x7fffffff56d7: false, bDependencyCheckFailed=@0x7fffffff56d6: false, nStartOffset=0, nEndOffset=3)
    at sc/source/core/data/formulacell.cxx:4829

so the CheckComputeDependencies at the start of 
ScFormulaCell::InterpretFormulaGroupThreading
is successful for aPos of {nRow = 1, nCol = 1, nTab = 3 }
and the cell is not dirty at that point

*however* in the following loop of 
for (SCCOL nCurrCol = nColStart; nCurrCol <= nColEnd; ++nCurrCol)
in InterpretFormulaGroupThreading, CheckComputeDependencies for
column 3 is called and the breakpoint #2 is hit, in this case
mxGroup->mbPartOfCycle is true and the {nRow = 1, nCol = 0, nTab = 3 }
cell is set dirty again.

so later during the threaded calculation the cell is found dirty and
the ScFormulaCell::MaybeInterpret() assert that !rDocument.IsThreadedGroupCalcInProgress()
first :-(
Comment 1 Caolán McNamara 2023-08-08 15:55:10 UTC
Created attachment 188853 [details]
fairly small example I can reproduce this with
Comment 2 Commit Notification 2023-08-14 08:33:17 UTC
Caolán McNamara committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4403b4e6bac19d89afded080d80de049aaa294ca

tdf#156677 if CheckComputeDependencies failed in expanded range...

It will be available in 24.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.