microsoft / microsoft/coyote

InvalidProgramException while trying coyote on my library.

Open
#433 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area-binary-rewriting bug
Dominant language
C#
Stars
1.6k
Forks
92
Avg merge
44m
Merged PRs (30d)
1

Description

Hello,
I wanted to test out coyote to try to find bugs in my MQTT Library.

Sadly it looks like the IL rewrite has a problematic bug:

Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at CK.MQTT.Client.Tests.Helpers.ApplicationMessageExtensions.PublishAsync(TestMQTTClient this, ApplicationMessage message)
   at CK.MQTT.Client.Tests.CoyoteTests.simple_publish_qos2_works_Async()
   at Microsoft.Coyote.Runtime.CoyoteRuntime.<>c__DisplayClass59_0.<RunTestAsync>b__0() in D:\a\1\s\Source\Core\Runtime\CoyoteRuntime.cs:line 373
   at Microsoft.Coyote.Runtime.CoyoteRuntime.<>c__DisplayClass62_0.<ScheduleOperation>b__0() in D:\a\1\s\Source\Core\Runtime\CoyoteRuntime.cs:line 467

The corrupted method do something a bit unusual:

        public static ValueTask<Task> PublishAsync( this TestMQTTClient @this, ApplicationMessage message )
            => @this.PublishAsync( message.Topic, message.QoS, message.Retain, message.Payload );

And the IL Diff:

"FullName": "CK.MQTT.Client.Tests.Helpers.ApplicationMessageExtensions",
"Methods": [
  {
    "Name": "PublishAsync",
    "FullName": "System.Threading.Tasks.ValueTask`1<System.Threading.Tasks.Task> CK.MQTT.Client.Tests.Helpers.ApplicationMessageExtensions::PublishAsync(CK.MQTT.Client.TestMQTTClient,CK.MQTT.Client.ApplicationMessage)",
    "Instructions": [
      "[-] IL_001e: ret",
      "[+] IL_001e: ldstr \"CK.MQTT.SmallOutgoingApplicationMessageExtensions.PublishAsync\"",
      "[+] IL_0023: call System.Threading.Tasks.ValueTask`1<TResult>& Microsoft.Coyote.Runtime.ExceptionProvider::ThrowIfReturnedValueTaskNotControlled<System.Threading.Tasks.Task>(System.Threading.Tasks.ValueTask`1<TResult>&,System.String)",
      "[+] IL_0028: ret"
    ]
  }
]

If you need to reproduce it, I made a branch on my repo:
https://github.com/signature-opensource/CK-MQTT/tree/testing-coyote

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the testing-coyote branch in CK-MQTT and inspect the reported IL diff for ApplicationMessageExtensions.PublishAsync. Start with the CoyoteRuntime.cs call sites at lines 373 and 467, then trace the IL rewrite that adds ExceptionProvider.ThrowIfReturnedValueTaskNotControlled. Done means the rewritten method no longer produces InvalidProgramException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
testing, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.