Skip to content

Mosek license leak #679

@Andreas-naut

Description

@Andreas-naut

Version Checks (indicate both or one)

  • I have confirmed this bug exists on the lastest release of Linopy.

  • I have confirmed this bug exists on the current master branch of Linopy.

Issue Description

Hi,

Mosek licenses are bound to the environment and within several Tasks can be created. solver.py calls mosek.Task() without explicit environment and that creates a "private linopy" env. Even if you're not aiming to run a mosek solve you're blocking a license it seems.
Full disclosure: Claude found this, I can't really vogue for this. It seems to be sure though, but they always are. But it seems to fix the leak.

_PATCH_FROM = (
" with contextlib.suppress(mosek.Error):\n"
" t = mosek.Task()\n"
" t.optimize()\n"
"\n"
" available_solvers.append("mosek")"
)

_PATCH_TO = (
" # PATCHED by linopy_mosek_probe_fix: use a context-managed Env+Task\n"
" # so the probe does not leak a PTS license token forever.\n"
" with contextlib.suppress(mosek.Error):\n"
" with mosek.Env() as _probe_env, _probe_env.Task(0, 0) as _probe_task:\n"
" _probe_task.optimize()\n"
" available_solvers.append("mosek")"
)

Cheers,
Andreas

Reproducible Example

see above

Expected Behavior

see above

Installed Versions

Details Replace this line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions