Skip to content

Commit d26ed7f

Browse files
committed
Update cabal.project and LanguageServer for improved logging and update to use new lsp revision
1 parent 5835ad7 commit d26ed7f

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

.github/workflows/flakiness.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ on:
3434

3535
jobs:
3636
loop:
37-
name: open-close loop (${{ matrix.os }})
37+
name: Flakiness Test (broken pipe and test failures)
3838
runs-on: ${{ matrix.os }}
3939
strategy:
4040
fail-fast: false
@@ -72,12 +72,12 @@ jobs:
7272
max_iter="${{ inputs.max_iter || '100' }}"
7373
bash scripts/open-close-loop.sh "${max_iter}"
7474
ec=$?
75-
# Interpret: 1 = flake reproduced (fail the job), 1 = not reproduced within budget (pass), others = infra error
76-
if [[ $ec -eq 1 ]]; then
77-
echo "Broken pipe reproduced: marking job as failed"
75+
# Interpret: 0 = issue reproduced (fail the job), 1 = not reproduced within budget (pass), others = infra error
76+
if [[ $ec -eq 0 ]]; then
77+
echo "Issue reproduced (broken pipe or test failure): marking job as failed"
7878
exit 1
79-
elif [[ $ec -eq 0 ]]; then
80-
echo "No flake reproduced within MAX_ITER=${max_iter}: passing"
79+
elif [[ $ec -eq 1 ]]; then
80+
echo "No issues reproduced within MAX_ITER=${max_iter}: passing"
8181
exit 0
8282
else
8383
echo "Loop script error (exit $ec): failing"

cabal.project

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ packages:
55
./ghcide
66
./hls-plugin-api
77
./hls-test-utils
8-
-- /Volumes/src/lsp/lsp
9-
-- /Volumes/src/lsp/lsp-types
10-
-- /Volumes/src/lsp/lsp-test
118

129

1310
index-state: 2025-08-08T12:31:54Z
@@ -63,5 +60,5 @@ if impl(ghc >= 9.11)
6360
source-repository-package
6461
type: git
6562
location: https://github.com/soulomoon/lsp.git
66-
tag: 4b57c8af1b5544c88bb040cf07132e611c5a0014
63+
tag: 47b70011cae725233f0c5ebdf7141d5de0b3066e
6764
subdir: lsp lsp-types lsp-test

ghcide/src/Development/IDE/LSP/LanguageServer.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Development.IDE.LSP.LanguageServer
1313
, runWithWorkerThreads
1414
, Setup (..)
1515
, InitializationContext (..)
16+
, untilMVar'
1617
) where
1718

1819
import Control.Concurrent.STM
@@ -64,10 +65,15 @@ data Log
6465
| LogLspServer LspServerLog
6566
| LogServerShutdownMessage
6667
| LogShutDownTimeout Int
68+
| LogServerExitWith (Either () Int)
6769
deriving Show
6870

6971
instance Pretty Log where
7072
pretty = \case
73+
LogServerExitWith (Right code) ->
74+
"Server exited with code" <+> pretty code
75+
LogServerExitWith (Left _) ->
76+
"Server forcefully exited due to exception in reactor thread"
7177
LogShutDownTimeout seconds ->
7278
"Shutdown timeout, the server will exit now after waiting for" <+> pretty seconds <+> "milliseconds"
7379
LogRegisteringIdeConfig ideConfig ->
@@ -169,7 +175,8 @@ runLanguageServer recorder options inH outH defaultConfig parseConfig onConfigCh
169175
outH
170176
serverDefinition
171177

172-
untilMVar clientMsgVar $ runServer `finally` sequence_ onExit
178+
untilMVar' clientMsgVar runServer `finally` sequence_ onExit
179+
>>= logWith recorder Info . LogServerExitWith
173180

174181
setupLSP ::
175182
forall config.
@@ -340,6 +347,9 @@ runWithWorkerThreads recorder dbLoc f = evalContT $ do
340347
untilMVar :: MonadUnliftIO m => MVar () -> m a -> m ()
341348
untilMVar mvar io = race_ (readMVar mvar) io
342349

350+
untilMVar' :: MonadUnliftIO m => MVar a -> m b -> m (Either a b)
351+
untilMVar' mvar io = race (readMVar mvar) io
352+
343353
cancelHandler :: (SomeLspId -> IO ()) -> LSP.Handlers (ServerM c)
344354
cancelHandler cancelRequest = LSP.notificationHandler SMethod_CancelRequest $ \TNotificationMessage{_params=CancelParams{_id}} ->
345355
liftIO $ cancelRequest (SomeLspId (toLspId _id))

scripts/open-close-loop.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# Loop running the "open close" test until a Broken pipe is observed.
2+
# Loop running the "open close" test until a Broken pipe or test failure is observed.
33
# Writes each iteration's full output to test-logs/open-close-loop-<n>.log
44
# Environment you can tweak:
55
# MAX_ITER : maximum iterations before giving up (default: unlimited)
@@ -8,7 +8,7 @@
88
# LOG_STDERR : set to 1 to enable verbose stderr logging (HLS_TEST_LOG_STDERR & HLS_TEST_HARNESS_STDERR) (default: 1)
99
#
1010
# Exit codes:
11-
# 0 on success (broken pipe reproduced)
11+
# 0 on success (broken pipe or test failure reproduced)
1212
# 1 on reaching MAX_ITER without reproduction
1313
# 2 on other setup error
1414

@@ -30,8 +30,9 @@ iter=0
3030
start_ts=$(date -Iseconds)
3131
echo "[loop] Starting at ${start_ts}" >&2
3232

33-
# Pattern string to detect (keep simple & literal for robustness)
33+
# Pattern strings to detect issues (keep simple & literal for robustness)
3434
BROKEN_PIPE_RE='Broken pipe'
35+
TEST_FAILED_RE='tests failed'
3536
DEBUG_DETECT="${DEBUG_DETECT:-0}"
3637

3738
if [[ -z "${NO_BUILD_ONCE:-}" ]]; then
@@ -79,19 +80,24 @@ while true; do
7980
echo "[loop] Broken pipe reproduced in iteration ${iter}. Stopping." | tee -a "${log}" >&2
8081
echo "[loop] --- Tail (last 60 lines) ---" >&2
8182
tail -n 60 "${log}" >&2
82-
exit 1
83+
exit 0
84+
elif grep -aFq -- "${TEST_FAILED_RE}" "${log}"; then
85+
echo "[loop] Test failure detected in iteration ${iter}. Stopping." | tee -a "${log}" >&2
86+
echo "[loop] --- Tail (last 60 lines) ---" >&2
87+
tail -n 60 "${log}" >&2
88+
exit 0
8389
else
8490
if [[ ${DEBUG_DETECT} -eq 1 ]]; then
85-
echo "[loop][debug] No match for '${BROKEN_PIPE_RE}' in iteration ${iter}." | tee -a "${log}" >&2
91+
echo "[loop][debug] No match for '${BROKEN_PIPE_RE}' or '${TEST_FAILED_RE}' in iteration ${iter}." | tee -a "${log}" >&2
8692
fi
8793
fi
8894

8995
if [[ -n "${MAX_ITER}" && ${iter} -ge ${MAX_ITER} ]]; then
90-
echo "[loop] Reached MAX_ITER=${MAX_ITER} without reproducing Broken pipe." >&2
91-
exit 0
96+
echo "[loop] Reached MAX_ITER=${MAX_ITER} without reproducing issues." >&2
97+
exit 1
9298
fi
9399

94-
echo "[loop] Iteration ${iter} complete (exit code ${ec}). No Broken pipe yet." | tee -a "${log}" >&2
100+
echo "[loop] Iteration ${iter} complete (exit code ${ec}). No issues detected yet." | tee -a "${log}" >&2
95101
if [[ ${SLEEP_SECS} -gt 0 ]]; then
96102
echo "[loop] Sleeping ${SLEEP_SECS}s" | tee -a "${log}" >&2
97103
sleep "${SLEEP_SECS}"

0 commit comments

Comments
 (0)