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

fix: ensure stream is closed after being read from app-dev's GetDefinitions method #14334

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions backend/src/Designer/Controllers/ProcessModelingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,19 @@ public async Task<IActionResult> UpsertProcessDefinitionAndNotify(string org, st
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase })
: null;

Stream stream = content.OpenReadStream();

string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer);

await using Stream stream = content.OpenReadStream();
try
{
await Guard.AssertValidXmlStreamAndRewindAsync(stream);
await _processModelingService.SaveProcessDefinitionAsync(editingContext, stream, cancellationToken);
}
catch (ArgumentException)
{
return BadRequest("BPMN file is not valid XML");
}

string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer);
await _processModelingService.SaveProcessDefinitionAsync(editingContext, stream, cancellationToken);

if (metadataObject?.TaskIdChange is not null)
{
await _mediator.Publish(new ProcessTaskIdChangedEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,18 @@
public Definitions GetDefinitions()
{
Stream processDefinitionStream = GetProcessDefinitionFile();

MemoryStream memoryStream = new MemoryStream();
Fixed Show fixed Hide fixed
processDefinitionStream.CopyTo(memoryStream);

memoryStream.Position = 0;

XmlSerializer serializer = new(typeof(Definitions));
return (Definitions)serializer.Deserialize(processDefinitionStream);
Definitions definitions = (Definitions)serializer.Deserialize(memoryStream);

processDefinitionStream.Close();

return definitions;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class EndpointNameSyncEvaluator : IRequestSyncEvaluator
nameof(ProcessModelingController.AddDataTypeToApplicationMetadata),
nameof(ProcessModelingController.DeleteDataTypeFromApplicationMetadata),
nameof(ProcessModelingController.UpsertProcessDefinitionAndNotify),
nameof(ProcessModelingController.ProcessDataTypesChangedNotify),
nameof(ProcessModelingController.SaveProcessDefinitionFromTemplate)
)
},
Expand Down
Loading