← Back to team overview

openjdk team mailing list archive

[Bug 1928334] [NEW] openjdk 11 crash with SIGSEGV (0xb) at pc=0x00007f879bce3ec8, pid=9190, tid=9262 using opencv 4.5.1 on ubuntu 20.04

 

Public bug reported:

I'm creating a sprin boot application that use opncv to read read n cams using rstp protocol an send images to am angular frontend.
After a few the java application died with this error:

    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    #  SIGSEGV (0xb) at pc=0x00007f879bce3ec8, pid=9190, tid=9262
    #
    # JRE version: OpenJDK Runtime Environment (11.0.11+9) (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
    # Java VM: OpenJDK 64-Bit Server VM (11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
    # Problematic frame:
    # C  [libc.so.6+0xbeec8]
    #
    # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/pietro/data/passportWS/opencv-facedetection-master/core.9190)
    #
    # An error report file with more information is saved as:
    # /home/pietro/data/passportWS/opencv-facedetection-master/hs_err_pid9190.log
    #
    # If you would like to submit a bug report, please visit:
    #   https://bugs.launchpad.net/ubuntu/+source/openjdk-lts
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    #
the code is above

    @Slf4j
    public class WebCamService {
	public WebCamService(WebCam camData) {
		cam.setName(camData.getName());
		String url;
		if ( Strings.allHaveText(camData.getLogin(), camData.getPassword() ) ) {
			url = String.format( CREDENTIAL_URL_TEMPLATE, Utils.getUrlProtocol( camData.getUrl() ),camData.getLogin(), camData.getPassword(), Utils.getUrlAddress( camData.getUrl() ) );
		} else {
			url = camData.getUrl();
		}
		cam.setHost( url );
		this.id = camData.getId();

		if ( Strings.hasText( camData.getSilhouettes() ) ) {
			types = Arrays.asList( camData.getSilhouettes().split(",") );
		} else {
			types = new ArrayList<String>();
		}
	}

	private static final String CREDENTIAL_URL_TEMPLATE = "%s://%s:%s@%s";
	private static final String TOPIC_TEMPLATE = "/topic/%s%s";
	private static final String IMG_VIDEO_TEMPLATE = "%s/%s";
	
	private List<String> types;
	
	@Autowired
    private SimpMessagingTemplate template;

    @Autowired
    private NeuralProcessor neuralProcessor;
	private WebCamViewer cam = new WebCamViewer();

	private ExecutorService read;
	
	private ExecutorService work;
	
	@Value("${video.dir.path}")
	private String videoDirPath;
	
	@Value("${image.dir.path}")
	private String imageDirPath;
	
	private AtomicBoolean screenshot = new AtomicBoolean(false);

	private Long id;
	
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public boolean startCam() {
		cam.open();

		if (!cam.isOpened()) {
			log.error("Error opening video camera {}", cam.getName() );
		} else {
			read = Executors.newSingleThreadExecutor();
			work = Executors.newSingleThreadExecutor();
			String streamTopic = String.format( TOPIC_TEMPLATE, "", getId() );
			String screenTopic = String.format( TOPIC_TEMPLATE, "screen_", getId() );
			
			
			log.info("Video camera {} is opened", cam.getName() );
			
			Object _self = this;

			AtomicReference<Mat> atomicFrame = new AtomicReference<Mat>();
			read.execute(() -> {
				Mat f = new Mat();
				int idx = 0;
				while (!read.isShutdown() && cam.isOpened()) {
					
					synchronized (_self) {
						f.release();
						if ( cam.read(f) ) {
							atomicFrame.set(f);
						}
					}
	
				}
			});
			work.execute(() -> {
				int counter = 0;
				int err = 0;
				Mat f = new Mat();
				List<DnnObject> objs = new ArrayList<DnnObject>();
				while (!work.isShutdown() && cam.isOpened()) {
					Mat frame = null;
					synchronized (_self) {
						frame = atomicFrame.get();
						if ( frame != null ) {
							frame.copyTo(f);
							frame = f;
						}
					}
					
					if (frame != null) {
						if (frame.empty()) {
							err++;
						} else {
							err = 0;
							if (++counter % 15 == 0) {
								counter = 0;
								neuralProcessor.getObjectsInFrame(objs,frame, false, types);
							}
							if ( screenshot.get() ) {
								try {
									if ( Utils.saveImage( frame, Utils.generateFilename( String.format(IMG_VIDEO_TEMPLATE, imageDirPath, cam.getName() ), "jpg" )  ) ) {
										this.template.convertAndSend( screenTopic, Utils.getBase64( frame ) );
										screenshot.set(false);
									}
								} catch (MessagingException e) {
									log.error("Error sending topic of screenshoot {}", e);
								} catch (IOException e) {
									log.error("Error sending topic of screenshoot {}", e);
								}
							}
							final Mat f1 = frame;
							objs.forEach(obj -> Imgproc.rectangle(f1, obj.getRightTop(), obj.getLeftBottom(), new Scalar(255, 255, 0) ) );
						    try {
								this.template.convertAndSend(streamTopic, Utils.getBase64(frame));
							} catch (MessagingException e) {
								log.error("Error sending topic {}", e);
							} catch (IOException e) {
								log.error("Error sending topic {}", e);
							}
						}
						frame.release();
						if (err >= 10) {
							stopCam();
						}
					}
				}
			});
		}
		return cam.isOpened();
	}

	public boolean stopCam() {
		stopRecording();
		if ( read != null && !read.isTerminated() ) {
			read.shutdown();
		}
		if ( work != null && !work.isTerminated() ) {
			work.shutdown();
		}
		cam.close();
		return !cam.isOpened();
	}
	public void takeScreenshot() {
		if ( cam.isOpened() ) {
			screenshot.set( true );
		}
	}

	public boolean isOn() {
		return cam.isOpened();
	}
    }

where WebCamViewer is a simple wrapper of VideoCapture.

In the spring-boot starter class there is an executor that every 30
seconds call

    System.runFinalization();
	System.gc();

I'd appreciate any advice or direction on how to solve this, thanks
    
full statck trace here https://drive.google.com/file/d/114FV0dZ3a_nXIYUrR8SBrXp-lBwuPojd/view?usp=sharing

** Affects: openjdk-lts (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of OpenJDK,
which is subscribed to openjdk-lts in Ubuntu.
https://bugs.launchpad.net/bugs/1928334

Title:
  openjdk 11 crash with SIGSEGV (0xb) at pc=0x00007f879bce3ec8,
  pid=9190, tid=9262 using opencv 4.5.1 on ubuntu 20.04

Status in openjdk-lts package in Ubuntu:
  New

Bug description:
  I'm creating a sprin boot application that use opncv to read read n cams using rstp protocol an send images to am angular frontend.
  After a few the java application died with this error:

      #
      # A fatal error has been detected by the Java Runtime Environment:
      #
      #  SIGSEGV (0xb) at pc=0x00007f879bce3ec8, pid=9190, tid=9262
      #
      # JRE version: OpenJDK Runtime Environment (11.0.11+9) (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
      # Java VM: OpenJDK 64-Bit Server VM (11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
      # Problematic frame:
      # C  [libc.so.6+0xbeec8]
      #
      # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/pietro/data/passportWS/opencv-facedetection-master/core.9190)
      #
      # An error report file with more information is saved as:
      # /home/pietro/data/passportWS/opencv-facedetection-master/hs_err_pid9190.log
      #
      # If you would like to submit a bug report, please visit:
      #   https://bugs.launchpad.net/ubuntu/+source/openjdk-lts
      # The crash happened outside the Java Virtual Machine in native code.
      # See problematic frame for where to report the bug.
      #
  the code is above

      @Slf4j
      public class WebCamService {
  	public WebCamService(WebCam camData) {
  		cam.setName(camData.getName());
  		String url;
  		if ( Strings.allHaveText(camData.getLogin(), camData.getPassword() ) ) {
  			url = String.format( CREDENTIAL_URL_TEMPLATE, Utils.getUrlProtocol( camData.getUrl() ),camData.getLogin(), camData.getPassword(), Utils.getUrlAddress( camData.getUrl() ) );
  		} else {
  			url = camData.getUrl();
  		}
  		cam.setHost( url );
  		this.id = camData.getId();

  		if ( Strings.hasText( camData.getSilhouettes() ) ) {
  			types = Arrays.asList( camData.getSilhouettes().split(",") );
  		} else {
  			types = new ArrayList<String>();
  		}
  	}

  	private static final String CREDENTIAL_URL_TEMPLATE = "%s://%s:%s@%s";
  	private static final String TOPIC_TEMPLATE = "/topic/%s%s";
  	private static final String IMG_VIDEO_TEMPLATE = "%s/%s";
  	
  	private List<String> types;
  	
  	@Autowired
      private SimpMessagingTemplate template;

      @Autowired
      private NeuralProcessor neuralProcessor;
  	private WebCamViewer cam = new WebCamViewer();

  	private ExecutorService read;
  	
  	private ExecutorService work;
  	
  	@Value("${video.dir.path}")
  	private String videoDirPath;
  	
  	@Value("${image.dir.path}")
  	private String imageDirPath;
  	
  	private AtomicBoolean screenshot = new AtomicBoolean(false);

  	private Long id;
  	
  	public Long getId() {
  		return id;
  	}
  	
  	public void setId(Long id) {
  		this.id = id;
  	}
  	
  	public boolean startCam() {
  		cam.open();

  		if (!cam.isOpened()) {
  			log.error("Error opening video camera {}", cam.getName() );
  		} else {
  			read = Executors.newSingleThreadExecutor();
  			work = Executors.newSingleThreadExecutor();
  			String streamTopic = String.format( TOPIC_TEMPLATE, "", getId() );
  			String screenTopic = String.format( TOPIC_TEMPLATE, "screen_", getId() );
  			
  			
  			log.info("Video camera {} is opened", cam.getName() );
  			
  			Object _self = this;

  			AtomicReference<Mat> atomicFrame = new AtomicReference<Mat>();
  			read.execute(() -> {
  				Mat f = new Mat();
  				int idx = 0;
  				while (!read.isShutdown() && cam.isOpened()) {
  					
  					synchronized (_self) {
  						f.release();
  						if ( cam.read(f) ) {
  							atomicFrame.set(f);
  						}
  					}
  	
  				}
  			});
  			work.execute(() -> {
  				int counter = 0;
  				int err = 0;
  				Mat f = new Mat();
  				List<DnnObject> objs = new ArrayList<DnnObject>();
  				while (!work.isShutdown() && cam.isOpened()) {
  					Mat frame = null;
  					synchronized (_self) {
  						frame = atomicFrame.get();
  						if ( frame != null ) {
  							frame.copyTo(f);
  							frame = f;
  						}
  					}
  					
  					if (frame != null) {
  						if (frame.empty()) {
  							err++;
  						} else {
  							err = 0;
  							if (++counter % 15 == 0) {
  								counter = 0;
  								neuralProcessor.getObjectsInFrame(objs,frame, false, types);
  							}
  							if ( screenshot.get() ) {
  								try {
  									if ( Utils.saveImage( frame, Utils.generateFilename( String.format(IMG_VIDEO_TEMPLATE, imageDirPath, cam.getName() ), "jpg" )  ) ) {
  										this.template.convertAndSend( screenTopic, Utils.getBase64( frame ) );
  										screenshot.set(false);
  									}
  								} catch (MessagingException e) {
  									log.error("Error sending topic of screenshoot {}", e);
  								} catch (IOException e) {
  									log.error("Error sending topic of screenshoot {}", e);
  								}
  							}
  							final Mat f1 = frame;
  							objs.forEach(obj -> Imgproc.rectangle(f1, obj.getRightTop(), obj.getLeftBottom(), new Scalar(255, 255, 0) ) );
  						    try {
  								this.template.convertAndSend(streamTopic, Utils.getBase64(frame));
  							} catch (MessagingException e) {
  								log.error("Error sending topic {}", e);
  							} catch (IOException e) {
  								log.error("Error sending topic {}", e);
  							}
  						}
  						frame.release();
  						if (err >= 10) {
  							stopCam();
  						}
  					}
  				}
  			});
  		}
  		return cam.isOpened();
  	}

  	public boolean stopCam() {
  		stopRecording();
  		if ( read != null && !read.isTerminated() ) {
  			read.shutdown();
  		}
  		if ( work != null && !work.isTerminated() ) {
  			work.shutdown();
  		}
  		cam.close();
  		return !cam.isOpened();
  	}
  	public void takeScreenshot() {
  		if ( cam.isOpened() ) {
  			screenshot.set( true );
  		}
  	}

  	public boolean isOn() {
  		return cam.isOpened();
  	}
      }

  where WebCamViewer is a simple wrapper of VideoCapture.

  In the spring-boot starter class there is an executor that every 30
  seconds call

      System.runFinalization();
  	System.gc();

  I'd appreciate any advice or direction on how to solve this, thanks
      
  full statck trace here https://drive.google.com/file/d/114FV0dZ3a_nXIYUrR8SBrXp-lBwuPojd/view?usp=sharing

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/openjdk-lts/+bug/1928334/+subscriptions


Follow ups