Skip to content

[flutter_svg] SvgNetworkLoader never closes internal HTTP client #158928

Closed
flutter/packages
#8126

Description

@navaronbracke

Steps to reproduce

  1. Create a SvgNetworkLoader instance, without passing it a custom http client
  2. Call prepareMessage(), which will create an internal client
  3. The created client is never calling its close() method
    3a. I had hoped to demonstrate this with a test that enables leak tracking, but the HTTP client does not register itself with the memory allocations tooling

Expected results

The client is closed at the end of postMessage()

Actual results

If the SvgNetworkLoader is not provided with a client, its internal client is not cleaned up.

See https://github.com/flutter/packages/blob/main/third_party/packages/flutter_svg/lib/src/loaders.dart#L439-L442

Code sample

Code sample
import 'package:flutter_svg/svg.dart';

void main() async {
  const String url =
      'https://raw.githubusercontent.com/flutter/packages/b9ac917daeb0fbf5bd6ad4a7d2a69ab81749d767/third_party/packages/flutter_svg/example/assets/flutter_logo.svg';

  const SvgNetworkLoader loader = SvgNetworkLoader(url);

  await loader.prepareMessage(null);
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.6.1 23G93 darwin-x64, locale en-BE)
    • Flutter version 3.24.3 on channel stable at /Users/navaronbracke/Documents/flutter
    • Upstream repository [email protected]:navaronbracke/flutter.git
    • FLUTTER_GIT_URL = [email protected]:navaronbracke/flutter.git
    • Framework revision 2663184aa7 (9 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/navaronbracke/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/navaronbracke/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.95.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.100.0

[✓] Connected device (2 available)            
    • macOS (desktop) • macos  • darwin-x64     • macOS 14.6.1 23G93 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 131.0.6778.69

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Nov 15, 2024
  2. huycozy commented on Nov 15, 2024

    @huycozy
    Member

    The current package version: flutter_svg: 2.0.14

  3. added
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    p: flutter_svgThe Flutter SVG drawing packages
    and removed
    in triagePresently being triaged by the triage team
    on Nov 15, 2024
  4. derdilla commented on Nov 19, 2024

    @derdilla
    Contributor

    Hi, I would be interested to work on this.

  5. added
    P3Issues that are less important to the Flutter project
    on Nov 19, 2024
  6. added
    r: fixedIssue is closed as already fixed in a newer version
    on Nov 21, 2024
  7. github-actions commented on Dec 5, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectfound in release: 3.24Found to occur in 3.24has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_svgThe Flutter SVG drawing packagespackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions