Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP crash w/ Invalid_argument("List.combine") #1228

Open
ELLIOTTCABLE opened this issue Jan 31, 2024 · 3 comments
Open

LSP crash w/ Invalid_argument("List.combine") #1228

ELLIOTTCABLE opened this issue Jan 31, 2024 · 3 comments

Comments

@ELLIOTTCABLE
Copy link

I'm getting an lsp-server crash; it's not clear what initiates it, but it happens almost immediately after invoking ocaml.server.restart:

[Error - 7:39:15 PM] Server process exited with code 0.
detached: /-----------------------------------------------------------------------
| Internal error: Uncaught exception.
| Invalid_argument("List.combine")
| Raised at Stdlib.invalid_arg in file "stdlib.ml", line 30, characters 20-45
| Called from Stdlib__List.combine in file "list.ml", line 305, characters 36-49
| Called from Merlin_specific__Browse_raw.of_expression_desc in file "src/ocaml/merlin_specific/browse_raw.ml", line 392, characters 23-54
| Called from Merlin_specific__Browse_raw.fold_node in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 698, characters 2-24
| Called from Merlin_specific__Browse_raw.all_holes.aux in file "src/ocaml/merlin_specific/browse_raw.ml", line 987, characters 4-28
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression_desc in file "src/ocaml/merlin_specific/browse_raw.ml", line 326, characters 4-53
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression_desc in file "src/ocaml/merlin_specific/browse_raw.ml", line 326, characters 4-53
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_node in file "src/ocaml/merlin_specific/browse_raw.ml", line 575, characters 24-84
| Called from Merlin_specific__Browse_raw.list_fold in file "src/ocaml/merlin_specific/browse_raw.ml", line 236, characters 37-53
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.list_fold in file "src/ocaml/merlin_specific/browse_raw.ml", line 236, characters 37-53
| Called from Merlin_specific__Browse_raw.list_fold_with_next in file "src/ocaml/merlin_specific/browse_raw.ml", line 247, characters 59-84
| Called from Merlin_specific__Browse_raw.all_holes in file "src/ocaml/merlin_specific/browse_raw.ml", line 989, characters 2-20
| Called from Query_commands.dispatch.loc_and_types_of_holes in file "src/frontend/query_commands.ml", line 613, characters 15-42
| Called from Stdlib__List.map in file "list.ml", line 92, characters 20-23
| Called from Merlin_utils__Std.List.concat_map in file "src/utils/std.ml" (inlined), line 129, characters 32-42
| Called from Query_commands.dispatch in file "src/frontend/query_commands.ml", line 619, characters 4-51
| Called from Ocaml_lsp_server__Diagnostics.merlin_diagnostics.(fun) in file "ocaml-lsp-server/src/diagnostics.ml", line 339, characters 12-50
| Called from Merlin_utils__Std.let_ref in file "src/utils/std.ml", line 693, characters 8-12
| Re-raised at Merlin_utils__Std.let_ref in file "src/utils/std.ml", line 695, characters 30-39
| Called from Merlin_utils__Misc.try_finally in file "src/utils/misc.ml", line 45, characters 8-15
| Re-raised at Merlin_utils__Misc.try_finally in file "src/utils/misc.ml", line 62, characters 10-24
| Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
| Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
| Called from Merlin_kernel__Mocaml.with_state in file "src/kernel/mocaml.ml", line 18, characters 8-38
| Re-raised at Merlin_kernel__Mocaml.with_state in file "src/kernel/mocaml.ml", line 20, characters 42-53
| Called from Ocaml_lsp_server__Document.Single_pipeline.use.(fun) in file "ocaml-lsp-server/src/document.ml", line 147, characters 22-77
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/src/exn_with_backtrace.ml", line 9, characters 8-12
| Re-raised at Stdune__Exn.raise_with_backtrace in file "otherlibs/stdune/src/exn.ml" (inlined), line 36, characters 27-56
| Called from Stdune__Exn_with_backtrace.reraise in file "otherlibs/stdune/src/exn_with_backtrace.ml", line 18, characters 33-71
| Called from Fiber__Core.O.(>>|).(fun) in file "fiber/src/core.ml", line 250, characters 36-41
| Called from Fiber__Scheduler.exec in file "fiber/src/scheduler.ml", line 73, characters 8-11
\-----------------------------------------------------------------------

The only invocation of List.combine seems to be here:

https://github.com/ocaml/merlin/blob/v4.11-414/src/ocaml/merlin_specific/browse_raw.ml#L382-L393

File contents
open Printf
open Lwt.Syntax

let show_option o = Option.value ~default:"<none>" o

let create_random_large_value size =
   let chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" in
   let chars_len = String.length chars in
   let result = Bytes.create size in
   for i = 0 to size - 1 do
     Bytes.set result i chars.[Random.int chars_len]
   done ;
   Bytes.to_string result


let create_and_leak_value size =
   let value = create_random_large_value size in
   let key = Lwt.new_key () in
   Lwt.bind (Lwt.return ()) (fun () ->
       let* () =
          Lwt.with_value key (Some value) (fun () ->
            (* test thing *)
            123
          )
       in
       printf "Gc.full_major ...\n%!" ;
       Gc.full_major () ;
       Lwt.return_unit)


let rec create_and_link_sequentially n size =
   match n with
   | 0 -> Lwt.return_unit
   | _ ->
       let* () = create_and_leak_value size in
       let* () = Lwt_unix.sleep 0.1 in
       create_and_link_sequentially (n - 1) size


let sleeper_and_leaker () =
   let leaker = create_and_link_sequentially 5 (1024 * 1024 * 10) in
   let sleeper = Lwt_unix.sleep 3. in
   let* (), () = Lwt.both sleeper leaker in
   Lwt.return_unit


let () =
   Memtrace.trace_if_requested ~sampling_rate:7e-6 ~context:"lwt leaking test" () ;

   Lwt_main.run @@ sleeper_and_leaker () ;

   printf "Gc.full_major ...\n%!" ;
   Gc.full_major ()
Full "OCaml Language Server" output pane contents
[Trace - 7:39:15 PM] Sending request 'shutdown - (5)'.
[Trace - 7:39:15 PM] Received response 'shutdown - (5)' in 0ms.
No result returned.


[Trace - 7:39:15 PM] Sending notification 'exit'.
No parameters provided.


halting dune merlin process
{ pid = pid 2836610; initial_cwd = "/home/me/code/ocaml-ambient-context" }
closed merlin process
{ pid = pid 2836610; initial_cwd = "/home/me/code/ocaml-ambient-context" }
[Trace - 7:39:15 PM] Sending request 'initialize - (0)'.
Params: {
    "processId": 2799344,
    "clientInfo": {
        "name": "Visual Studio Code",
        "version": "1.85.2"
    },
    "locale": "en",
    "rootPath": "/home/me/code/ocaml-ambient-context",
    "rootUri": "file:///home/me/code/ocaml-ambient-context",
    "capabilities": {
        "workspace": {
            "applyEdit": true,
            "workspaceEdit": {
                "documentChanges": true,
                "resourceOperations": [
                    "create",
                    "rename",
                    "delete"
                ],
                "failureHandling": "textOnlyTransactional",
                "normalizesLineEndings": true,
                "changeAnnotationSupport": {
                    "groupsOnLabel": true
                }
            },
            "configuration": true,
            "didChangeWatchedFiles": {
                "dynamicRegistration": true,
                "relativePatternSupport": true
            },
            "symbol": {
                "dynamicRegistration": true,
                "symbolKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25,
                        26
                    ]
                },
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "resolveSupport": {
                    "properties": [
                        "location.range"
                    ]
                }
            },
            "codeLens": {
                "refreshSupport": true
            },
            "executeCommand": {
                "dynamicRegistration": true
            },
            "didChangeConfiguration": {
                "dynamicRegistration": true
            },
            "workspaceFolders": true,
            "foldingRange": {
                "refreshSupport": true
            },
            "semanticTokens": {
                "refreshSupport": true
            },
            "fileOperations": {
                "dynamicRegistration": true,
                "didCreate": true,
                "didRename": true,
                "didDelete": true,
                "willCreate": true,
                "willRename": true,
                "willDelete": true
            },
            "inlineValue": {
                "refreshSupport": true
            },
            "inlayHint": {
                "refreshSupport": true
            },
            "diagnostics": {
                "refreshSupport": true
            }
        },
        "textDocument": {
            "publishDiagnostics": {
                "relatedInformation": true,
                "versionSupport": false,
                "tagSupport": {
                    "valueSet": [
                        1,
                        2
                    ]
                },
                "codeDescriptionSupport": true,
                "dataSupport": true
            },
            "synchronization": {
                "dynamicRegistration": true,
                "willSave": true,
                "willSaveWaitUntil": true,
                "didSave": true
            },
            "completion": {
                "dynamicRegistration": true,
                "contextSupport": true,
                "completionItem": {
                    "snippetSupport": true,
                    "commitCharactersSupport": true,
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "deprecatedSupport": true,
                    "preselectSupport": true,
                    "tagSupport": {
                        "valueSet": [
                            1
                        ]
                    },
                    "insertReplaceSupport": true,
                    "resolveSupport": {
                        "properties": [
                            "documentation",
                            "detail",
                            "additionalTextEdits"
                        ]
                    },
                    "insertTextModeSupport": {
                        "valueSet": [
                            1,
                            2
                        ]
                    },
                    "labelDetailsSupport": true
                },
                "insertTextMode": 2,
                "completionItemKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25
                    ]
                },
                "completionList": {
                    "itemDefaults": [
                        "commitCharacters",
                        "editRange",
                        "insertTextFormat",
                        "insertTextMode",
                        "data"
                    ]
                }
            },
            "hover": {
                "dynamicRegistration": true,
                "contentFormat": [
                    "markdown",
                    "plaintext"
                ]
            },
            "signatureHelp": {
                "dynamicRegistration": true,
                "signatureInformation": {
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "parameterInformation": {
                        "labelOffsetSupport": true
                    },
                    "activeParameterSupport": true
                },
                "contextSupport": true
            },
            "definition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "references": {
                "dynamicRegistration": true
            },
            "documentHighlight": {
                "dynamicRegistration": true
            },
            "documentSymbol": {
                "dynamicRegistration": true,
                "symbolKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25,
                        26
                    ]
                },
                "hierarchicalDocumentSymbolSupport": true,
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "labelSupport": true
            },
            "codeAction": {
                "dynamicRegistration": true,
                "isPreferredSupport": true,
                "disabledSupport": true,
                "dataSupport": true,
                "resolveSupport": {
                    "properties": [
                        "edit"
                    ]
                },
                "codeActionLiteralSupport": {
                    "codeActionKind": {
                        "valueSet": [
                            "",
                            "quickfix",
                            "refactor",
                            "refactor.extract",
                            "refactor.inline",
                            "refactor.rewrite",
                            "source",
                            "source.organizeImports"
                        ]
                    }
                },
                "honorsChangeAnnotations": true
            },
            "codeLens": {
                "dynamicRegistration": true
            },
            "formatting": {
                "dynamicRegistration": true
            },
            "rangeFormatting": {
                "dynamicRegistration": true,
                "rangesSupport": true
            },
            "onTypeFormatting": {
                "dynamicRegistration": true
            },
            "rename": {
                "dynamicRegistration": true,
                "prepareSupport": true,
                "prepareSupportDefaultBehavior": 1,
                "honorsChangeAnnotations": true
            },
            "documentLink": {
                "dynamicRegistration": true,
                "tooltipSupport": true
            },
            "typeDefinition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "implementation": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "colorProvider": {
                "dynamicRegistration": true
            },
            "foldingRange": {
                "dynamicRegistration": true,
                "rangeLimit": 5000,
                "lineFoldingOnly": true,
                "foldingRangeKind": {
                    "valueSet": [
                        "comment",
                        "imports",
                        "region"
                    ]
                },
                "foldingRange": {
                    "collapsedText": false
                }
            },
            "declaration": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "selectionRange": {
                "dynamicRegistration": true
            },
            "callHierarchy": {
                "dynamicRegistration": true
            },
            "semanticTokens": {
                "dynamicRegistration": true,
                "tokenTypes": [
                    "namespace",
                    "type",
                    "class",
                    "enum",
                    "interface",
                    "struct",
                    "typeParameter",
                    "parameter",
                    "variable",
                    "property",
                    "enumMember",
                    "event",
                    "function",
                    "method",
                    "macro",
                    "keyword",
                    "modifier",
                    "comment",
                    "string",
                    "number",
                    "regexp",
                    "operator",
                    "decorator"
                ],
                "tokenModifiers": [
                    "declaration",
                    "definition",
                    "readonly",
                    "static",
                    "deprecated",
                    "abstract",
                    "async",
                    "modification",
                    "documentation",
                    "defaultLibrary"
                ],
                "formats": [
                    "relative"
                ],
                "requests": {
                    "range": true,
                    "full": {
                        "delta": true
                    }
                },
                "multilineTokenSupport": false,
                "overlappingTokenSupport": false,
                "serverCancelSupport": true,
                "augmentsSyntaxTokens": true
            },
            "linkedEditingRange": {
                "dynamicRegistration": true
            },
            "typeHierarchy": {
                "dynamicRegistration": true
            },
            "inlineValue": {
                "dynamicRegistration": true
            },
            "inlayHint": {
                "dynamicRegistration": true,
                "resolveSupport": {
                    "properties": [
                        "tooltip",
                        "textEdits",
                        "label.tooltip",
                        "label.location",
                        "label.command"
                    ]
                }
            },
            "diagnostic": {
                "dynamicRegistration": true,
                "relatedDocumentSupport": false
            }
        },
        "window": {
            "showMessage": {
                "messageActionItem": {
                    "additionalPropertiesSupport": true
                }
            },
            "showDocument": {
                "support": true
            },
            "workDoneProgress": true
        },
        "general": {
            "staleRequestSupport": {
                "cancel": true,
                "retryOnContentModified": [
                    "textDocument/semanticTokens/full",
                    "textDocument/semanticTokens/range",
                    "textDocument/semanticTokens/full/delta"
                ]
            },
            "regularExpressions": {
                "engine": "ECMAScript",
                "version": "ES2020"
            },
            "markdown": {
                "parser": "marked",
                "version": "1.1.0"
            },
            "positionEncodings": [
                "utf-16"
            ]
        },
        "notebookDocument": {
            "synchronization": {
                "dynamicRegistration": true,
                "executionSummarySupport": true
            }
        },
        "experimental": {
            "jumpToNextHole": true
        }
    },
    "trace": "verbose",
    "workspaceFolders": [
        {
            "uri": "file:///home/me/code/ocaml-ambient-context",
            "name": "ocaml-ambient-context"
        }
    ]
}


[Trace - 7:39:15 PM] Received notification 'window/logMessage'.
Params: {
    "message": "failed to poll dune registry.\nUnix.Unix_error(Unix.ENOENT, \"stat\", \"/run/user/2040/dune/rpc\")\nMaybe you are not running dune in watch mode?\nHint: $ dune build -w",
    "type": 2
}


[Warn  - 7:39:15 PM] failed to poll dune registry.
Unix.Unix_error(Unix.ENOENT, "stat", "/run/user/2040/dune/rpc")
Maybe you are not running dune in watch mode?
Hint: $ dune build -w
[Trace - 7:39:15 PM] Received response 'initialize - (0)' in 19ms.
Result: {
    "capabilities": {
        "codeActionProvider": {
            "codeActionKinds": [
                "quickfix",
                "refactor.inline",
                "construct",
                "destruct",
                "inferred_intf",
                "put module name in identifiers",
                "remove module name from identifiers",
                "remove type annotation",
                "type-annotate"
            ]
        },
        "codeLensProvider": {
            "resolveProvider": false
        },
        "completionProvider": {
            "resolveProvider": true,
            "triggerCharacters": [
                ".",
                "#"
            ]
        },
        "declarationProvider": true,
        "definitionProvider": true,
        "documentFormattingProvider": true,
        "documentHighlightProvider": true,
        "documentSymbolProvider": true,
        "executeCommandProvider": {
            "commands": [
                "ocamllsp/view-metrics",
                "ocamllsp/open-related-source",
                "ocamllsp/show-document-text",
                "ocamllsp/show-merlin-config",
                "dune/promote"
            ]
        },
        "experimental": {
            "ocamllsp": {
                "interfaceSpecificLangId": true,
                "handleSwitchImplIntf": true,
                "handleInferIntf": true,
                "handleTypedHoles": true,
                "handleWrappingAstNode": true,
                "diagnostic_promotions": true,
                "handleHoverExtended": true
            }
        },
        "foldingRangeProvider": true,
        "hoverProvider": true,
        "positionEncoding": "utf-16",
        "referencesProvider": true,
        "renameProvider": {
            "prepareProvider": true
        },
        "selectionRangeProvider": true,
        "semanticTokensProvider": {
            "full": {
                "delta": true
            },
            "legend": {
                "tokenModifiers": [
                    "declaration",
                    "definition",
                    "readonly",
                    "static",
                    "deprecated",
                    "abstract",
                    "async",
                    "modification",
                    "documentation",
                    "defaultLibrary"
                ],
                "tokenTypes": [
                    "namespace",
                    "type",
                    "class",
                    "enum",
                    "interface",
                    "struct",
                    "typeParameter",
                    "parameter",
                    "variable",
                    "property",
                    "enumMember",
                    "event",
                    "function",
                    "method",
                    "macro",
                    "keyword",
                    "modifier",
                    "comment",
                    "string",
                    "number",
                    "regexp",
                    "operator",
                    "decorator"
                ]
            }
        },
        "signatureHelpProvider": {
            "triggerCharacters": [
                " ",
                "~",
                "?",
                ":",
                "("
            ]
        },
        "textDocumentSync": {
            "change": 2,
            "openClose": true,
            "save": {
                "includeText": false
            },
            "willSave": false,
            "willSaveWaitUntil": false
        },
        "typeDefinitionProvider": true,
        "workspace": {
            "workspaceFolders": {
                "changeNotifications": true,
                "supported": true
            }
        },
        "workspaceSymbolProvider": true
    },
    "serverInfo": {
        "name": "ocamllsp",
        "version": "1.17.0"
    }
}


[Trace - 7:39:15 PM] Sending notification 'initialized'.
Params: {}


[Trace - 7:39:15 PM] Received request 'client/registerCapability - (1)'.
Params: {
    "registrations": [
        {
            "id": "ocamllsp-cram-dune-files/textDocument/didOpen",
            "method": "textDocument/didOpen",
            "registerOptions": {
                "documentSelector": [
                    {
                        "language": "cram",
                        "scheme": null,
                        "pattern": null
                    },
                    {
                        "language": "dune",
                        "scheme": null,
                        "pattern": null
                    },
                    {
                        "language": "dune-project",
                        "scheme": null,
                        "pattern": null
                    },
                    {
                        "language": "dune-workspace",
                        "scheme": null,
                        "pattern": null
                    }
                ]
            }
        },
        {
            "id": "ocamllsp-cram-dune-files/textDocument/didClose",
            "method": "textDocument/didClose",
            "registerOptions": {
                "documentSelector": [
                    {
                        "language": "cram",
                        "scheme": null,
                        "pattern": null
                    },
                    {
                        "language": "dune",
                        "scheme": null,
                        "pattern": null
                    },
                    {
                        "language": "dune-project",
                        "scheme": null,
                        "pattern": null
                    },
                    {
                        "language": "dune-workspace",
                        "scheme": null,
                        "pattern": null
                    }
                ]
            }
        }
    ]
}


[Trace - 7:39:15 PM] Sending response 'client/registerCapability - (1)'. Processing request took 0ms
No result returned.


[Trace - 7:39:15 PM] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.ml",
        "languageId": "ocaml",
        "version": 1,
        "text": "open Printf\nopen Lwt.Syntax\n\nlet show_option o = Option.value ~default:\"<none>\" o\n\nlet create_random_large_value size =\n   let chars = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\" in\n   let chars_len = String.length chars in\n   let result = Bytes.create size in\n   for i = 0 to size - 1 do\n     Bytes.set result i chars.[Random.int chars_len]\n   done ;\n   Bytes.to_string result\n\n\nlet create_and_leak_value size =\n   let value = create_random_large_value size in\n   let key = Lwt.new_key () in\n   Lwt.bind (Lwt.return ()) (fun () ->\n       let* () =\n          Lwt.with_value key (Some value) (fun () ->\n            (* test thing *)\n            123\n          )\n       in\n       printf \"Gc.full_major ...\\n%!\" ;\n       Gc.full_major () ;\n       Lwt.return_unit)\n\n\nlet rec create_and_link_sequentially n size =\n   match n with\n   | 0 -> Lwt.return_unit\n   | _ ->\n       let* () = create_and_leak_value size in\n       let* () = Lwt_unix.sleep 0.1 in\n       create_and_link_sequentially (n - 1) size\n\n\nlet sleeper_and_leaker () =\n   let leaker = create_and_link_sequentially 5 (1024 * 1024 * 10) in\n   let sleeper = Lwt_unix.sleep 3. in\n   let* (), () = Lwt.both sleeper leaker in\n   Lwt.return_unit\n\n\nlet () =\n   Memtrace.trace_if_requested ~sampling_rate:7e-6 ~context:\"lwt leaking test\" () ;\n\n   Lwt_main.run @@ sleeper_and_leaker () ;\n\n   printf \"Gc.full_major ...\\n%!\" ;\n   Gc.full_major ()\n"
    }
}


[Trace - 7:39:15 PM] Sending notification 'workspace/didChangeConfiguration'.
Params: {
    "settings": {
        "codelens": {
            "enable": true
        },
        "extendedHover": {
            "enable": false
        },
        "duneDiagnostics": {
            "enable": true
        },
        "syntaxDocumentation": {
            "enable": false
        }
    }
}


[Trace - 7:39:15 PM] Sending request 'textDocument/codeAction - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.ml"
    },
    "range": {
        "start": {
            "line": 21,
            "character": 27
        },
        "end": {
            "line": 21,
            "character": 27
        }
    },
    "context": {
        "diagnostics": [],
        "triggerKind": 2
    }
}


[Trace - 7:39:15 PM] Received response 'textDocument/codeAction - (1)' in 15ms.
Result: [
    {
        "edit": {
            "documentChanges": [
                {
                    "edits": [
                        {
                            "newText": "(123 : int)",
                            "range": {
                                "end": {
                                    "character": 15,
                                    "line": 22
                                },
                                "start": {
                                    "character": 12,
                                    "line": 22
                                }
                            }
                        }
                    ],
                    "textDocument": {
                        "uri": "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.ml",
                        "version": 1
                    }
                }
            ]
        },
        "isPreferred": false,
        "kind": "type-annotate",
        "title": "Type-annotate"
    },
    {
        "command": {
            "arguments": [
                "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.mli"
            ],
            "command": "ocamllsp/open-related-source",
            "title": "Create test_lwt_leak.mli"
        },
        "edit": {
            "documentChanges": [
                {
                    "kind": "create",
                    "uri": "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.mli"
                }
            ]
        },
        "kind": "switch",
        "title": "Create test_lwt_leak.mli"
    }
]


[Error - 7:39:15 PM] Server process exited with code 0.
detached: /-----------------------------------------------------------------------
| Internal error: Uncaught exception.
| Invalid_argument("List.combine")
| Raised at Stdlib.invalid_arg in file "stdlib.ml", line 30, characters 20-45
| Called from Stdlib__List.combine in file "list.ml", line 305, characters 36-49
| Called from Merlin_specific__Browse_raw.of_expression_desc in file "src/ocaml/merlin_specific/browse_raw.ml", line 392, characters 23-54
| Called from Merlin_specific__Browse_raw.fold_node in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 698, characters 2-24
| Called from Merlin_specific__Browse_raw.all_holes.aux in file "src/ocaml/merlin_specific/browse_raw.ml", line 987, characters 4-28
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression_desc in file "src/ocaml/merlin_specific/browse_raw.ml", line 326, characters 4-53
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression_desc in file "src/ocaml/merlin_specific/browse_raw.ml", line 326, characters 4-53
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_node in file "src/ocaml/merlin_specific/browse_raw.ml", line 575, characters 24-84
| Called from Merlin_specific__Browse_raw.list_fold in file "src/ocaml/merlin_specific/browse_raw.ml", line 236, characters 37-53
| Called from Merlin_specific__Browse_raw.(**) in file "src/ocaml/merlin_specific/browse_raw.ml" (inlined), line 233, characters 11-25
| Called from Merlin_specific__Browse_raw.of_expression in file "src/ocaml/merlin_specific/browse_raw.ml", line 267, characters 22-78
| Called from Merlin_specific__Browse_raw.list_fold in file "src/ocaml/merlin_specific/browse_raw.ml", line 236, characters 37-53
| Called from Merlin_specific__Browse_raw.list_fold_with_next in file "src/ocaml/merlin_specific/browse_raw.ml", line 247, characters 59-84
| Called from Merlin_specific__Browse_raw.all_holes in file "src/ocaml/merlin_specific/browse_raw.ml", line 989, characters 2-20
| Called from Query_commands.dispatch.loc_and_types_of_holes in file "src/frontend/query_commands.ml", line 613, characters 15-42
| Called from Stdlib__List.map in file "list.ml", line 92, characters 20-23
| Called from Merlin_utils__Std.List.concat_map in file "src/utils/std.ml" (inlined), line 129, characters 32-42
| Called from Query_commands.dispatch in file "src/frontend/query_commands.ml", line 619, characters 4-51
| Called from Ocaml_lsp_server__Diagnostics.merlin_diagnostics.(fun) in file "ocaml-lsp-server/src/diagnostics.ml", line 339, characters 12-50
| Called from Merlin_utils__Std.let_ref in file "src/utils/std.ml", line 693, characters 8-12
| Re-raised at Merlin_utils__Std.let_ref in file "src/utils/std.ml", line 695, characters 30-39
| Called from Merlin_utils__Misc.try_finally in file "src/utils/misc.ml", line 45, characters 8-15
| Re-raised at Merlin_utils__Misc.try_finally in file "src/utils/misc.ml", line 62, characters 10-24
| Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
| Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
| Called from Merlin_kernel__Mocaml.with_state in file "src/kernel/mocaml.ml", line 18, characters 8-38
| Re-raised at Merlin_kernel__Mocaml.with_state in file "src/kernel/mocaml.ml", line 20, characters 42-53
| Called from Ocaml_lsp_server__Document.Single_pipeline.use.(fun) in file "ocaml-lsp-server/src/document.ml", line 147, characters 22-77
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/src/exn_with_backtrace.ml", line 9, characters 8-12
| Re-raised at Stdune__Exn.raise_with_backtrace in file "otherlibs/stdune/src/exn.ml" (inlined), line 36, characters 27-56
| Called from Stdune__Exn_with_backtrace.reraise in file "otherlibs/stdune/src/exn_with_backtrace.ml", line 18, characters 33-71
| Called from Fiber__Core.O.(>>|).(fun) in file "fiber/src/core.ml", line 250, characters 36-41
| Called from Fiber__Scheduler.exec in file "fiber/src/scheduler.ml", line 73, characters 8-11
\-----------------------------------------------------------------------

[Trace - 7:39:16 PM] Sending request 'textDocument/foldingRange - (2)'.
Params: {
    "textDocument": {
        "uri": "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.ml"
    }
}


[Trace - 7:39:16 PM] Received response 'textDocument/foldingRange - (2)' in 2ms.
Result: [
    {
        "endCharacter": 25,
        "endLine": 12,
        "kind": "region",
        "startCharacter": 0,
        "startLine": 5
    },
    {
        "endCharacter": 7,
        "endLine": 11,
        "kind": "region",
        "startCharacter": 3,
        "startLine": 9
    },
    {
        "endCharacter": 23,
        "endLine": 27,
        "kind": "region",
        "startCharacter": 0,
        "startLine": 15
    },
    {
        "endCharacter": 23,
        "endLine": 27,
        "kind": "region",
        "startCharacter": 3,
        "startLine": 18
    },
    {
        "endCharacter": 22,
        "endLine": 27,
        "kind": "region",
        "startCharacter": 7,
        "startLine": 19
    },
    {
        "endCharacter": 11,
        "endLine": 23,
        "kind": "region",
        "startCharacter": 10,
        "startLine": 20
    },
    {
        "endCharacter": 48,
        "endLine": 36,
        "kind": "region",
        "startCharacter": 0,
        "startLine": 30
    },
    {
        "endCharacter": 48,
        "endLine": 36,
        "kind": "region",
        "startCharacter": 3,
        "startLine": 31
    },
    {
        "endCharacter": 48,
        "endLine": 36,
        "kind": "region",
        "startCharacter": 6,
        "startLine": 33
    },
    {
        "endCharacter": 48,
        "endLine": 36,
        "kind": "region",
        "startCharacter": 7,
        "startLine": 34
    },
    {
        "endCharacter": 48,
        "endLine": 36,
        "kind": "region",
        "startCharacter": 7,
        "startLine": 35
    },
    {
        "endCharacter": 18,
        "endLine": 43,
        "kind": "region",
        "startCharacter": 0,
        "startLine": 39
    },
    {
        "endCharacter": 18,
        "endLine": 43,
        "kind": "region",
        "startCharacter": 3,
        "startLine": 42
    },
    {
        "endCharacter": 19,
        "endLine": 52,
        "kind": "region",
        "startCharacter": 0,
        "startLine": 46
    }
]


[Trace - 7:39:16 PM] Sending request 'textDocument/codeLens - (3)'.
Params: {
    "textDocument": {
        "uri": "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.ml"
    }
}


[Trace - 7:39:16 PM] Received response 'textDocument/codeLens - (3)' in 1ms.
Result: [
    {
        "command": {
            "command": "",
            "title": "unit -> unit Lwt.t"
        },
        "range": {
            "end": {
                "character": 18,
                "line": 43
            },
            "start": {
                "character": 0,
                "line": 39
            }
        }
    },
    {
        "command": {
            "command": "",
            "title": "int -> int -> unit Lwt.t"
        },
        "range": {
            "end": {
                "character": 48,
                "line": 36
            },
            "start": {
                "character": 0,
                "line": 30
            }
        }
    },
    {
        "command": {
            "command": "",
            "title": "int -> unit Lwt.t"
        },
        "range": {
            "end": {
                "character": 23,
                "line": 27
            },
            "start": {
                "character": 0,
                "line": 15
            }
        }
    },
    {
        "command": {
            "command": "",
            "title": "int -> string"
        },
        "range": {
            "end": {
                "character": 25,
                "line": 12
            },
            "start": {
                "character": 0,
                "line": 5
            }
        }
    },
    {
        "command": {
            "command": "",
            "title": "string option -> string"
        },
        "range": {
            "end": {
                "character": 52,
                "line": 3
            },
            "start": {
                "character": 0,
                "line": 3
            }
        }
    }
]


[Trace - 7:39:16 PM] Sending request 'textDocument/documentSymbol - (4)'.
Params: {
    "textDocument": {
        "uri": "file:///home/me/code/ocaml-ambient-context/test/memory/test_lwt_leak.ml"
    }
}


[Trace - 7:39:16 PM] Received response 'textDocument/documentSymbol - (4)' in 2ms.
Result: [
    {
        "children": [],
        "deprecated": false,
        "detail": "unit -> unit Lwt.t",
        "kind": 12,
        "name": "sleeper_and_leaker",
        "range": {
            "end": {
                "character": 18,
                "line": 43
            },
            "start": {
                "character": 0,
                "line": 39
            }
        },
        "selectionRange": {
            "end": {
                "character": 18,
                "line": 43
            },
            "start": {
                "character": 0,
                "line": 39
            }
        }
    },
    {
        "children": [],
        "deprecated": false,
        "detail": "int -> int -> unit Lwt.t",
        "kind": 12,
        "name": "create_and_link_sequentially",
        "range": {
            "end": {
                "character": 48,
                "line": 36
            },
            "start": {
                "character": 0,
                "line": 30
            }
        },
        "selectionRange": {
            "end": {
                "character": 48,
                "line": 36
            },
            "start": {
                "character": 0,
                "line": 30
            }
        }
    },
    {
        "children": [],
        "deprecated": false,
        "detail": "int -> unit Lwt.t",
        "kind": 12,
        "name": "create_and_leak_value",
        "range": {
            "end": {
                "character": 23,
                "line": 27
            },
            "start": {
                "character": 0,
                "line": 15
            }
        },
        "selectionRange": {
            "end": {
                "character": 23,
                "line": 27
            },
            "start": {
                "character": 0,
                "line": 15
            }
        }
    },
    {
        "children": [],
        "deprecated": false,
        "detail": "int -> string",
        "kind": 12,
        "name": "create_random_large_value",
        "range": {
            "end": {
                "character": 25,
                "line": 12
            },
            "start": {
                "character": 0,
                "line": 5
            }
        },
        "selectionRange": {
            "end": {
                "character": 25,
                "line": 12
            },
            "start": {
                "character": 0,
                "line": 5
            }
        }
    },
    {
        "children": [],
        "deprecated": false,
        "detail": "string option -> string",
        "kind": 12,
        "name": "show_option",
        "range": {
            "end": {
                "character": 52,
                "line": 3
            },
            "start": {
                "character": 0,
                "line": 3
            }
        },
        "selectionRange": {
            "end": {
                "character": 52,
                "line": 3
            },
            "start": {
                "character": 0,
                "line": 3
            }
        }
    }
]
Platform & versions
  • macOS “Sonoma” 14.2.1
  • VScode 1.85.2
  • VScode OCaml Platform: 1.17.0
  • OCaml: 4.14.1
  • ocaml-lsp-server: 1.17.0
@rgrinberg
Copy link
Member

cc @voodoos

@voodoos
Copy link
Collaborator

voodoos commented Feb 1, 2024

That's definitively a Merlin issue. We already fixed issues with that feature (my guess is that it's the let* (), () = Lwt.both sleeper leaker in expression that breaks merlin), @ELLIOTTCABLE could confirm that you are running the latest merlin-lib / ocaml-lsp versions ?

@voodoos
Copy link
Collaborator

voodoos commented Feb 15, 2024

@ELLIOTTCABLE

I just made a small project with your file, OCaml 4.14, ocaml-lsp-server 1.17.0 and merlin-lib 4.13-414 and I am not able to reproduce the crash with vscode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants