Rinse the duck under cold water and pat dry with absorbent paper towel.
Stuff the cavity of the duck with the onion wedges, 2 sprigs of thyme and, if desired, 1 sprig of rosemary. Bind the duck with kitchen twine.
Place the duck and legs in a roasting pan. Spread the remaining sprigs of thyme and rosemary, if using, around the duck. Add salt and pepper. Stick a cooking thermometer into one of the legs of the whole duck, without touching the bone.
In a bowl, whisk the port with the maple butter and duck stock. Add salt and pepper. Pour one-third of the mixture over the duck. Refrigerate the rest of the mixture.
Cover the roasting pan and bake for 2 hours.
Then, spoon the cooking juices over the duck. Continue roasting uncovered for 30 minutes, until the skin becomes crispy and the thermometer reads 82 °C (180 °F).
Remove from the oven and place the whole duck and legs in a serving dish. Cover loosely with a sheet of aluminum foil.
Remove the cooking fat from the roasting pan. Pour the rest of the port mixture into the roasting pan and bring to a boil, scraping the sides with a wooden spoon to remove the cooking juices. Transfer to a saucepan and heat over medium heat until the liquid has reduced by a third. Dissolve the cornstarch in a little cold water. Pour into the saucepan and bring to a boil. Simmer until thickened. Serve with the duck.