0

I am encountering an issue where a Spring Boot service, after running for about a day with some load, suddenly is unable to create a connection.

I used the standard Spring Boot 2 project starter. Created a rest controller, a model, a service, and a repository.

@Entity
@Table(name = "partners")
public class Partner {

    /** Unique identifier. */
    @Id
    @JsonProperty("id")
    private long id;

    /** Partner name. */
    @JsonProperty("name")
    private String name;

    /**
     * Default constructor. Not usable publicly.
     */
    protected Partner() {
    }

    // etc...
}

Repo

/**
 * Partner repo.
 */
public interface PartnerRepository extends CrudRepository<Partner, Long> {
}

The Service

@Service
public class PartnersService {

    /** Access to Partner repo. */
    @Autowired
    private PartnerRepository partnerRepo;

    /**
     * Get partner data.
     *
     * @param id Partner identifier.
     * @return Partner instance, or null if not found.
     */
    public Partner getPartner(final long id) throws ServiceException {
        if (id <= 0) {
            throw new ServiceException("Please enter a valid partner identifier.");
        }
        final Optional<Partner> partner = partnerRepo.findById(id);
        return partner.orElse(null);
    }
}

The Controller

@RestController
public class PartnerController extends BaseController {

    /** Partners service. */
    @Autowired
    private PartnersService partnersService;

    @RequestMapping(value = "/partners/api/v1/partners/{id}", method = GET)
    public ResponseEntity<FilldResponse> getPartner(@PathVariable final long id) {
        final FilldResponse response = new FilldResponse();
        HttpStatus httpStatus = HttpStatus.OK;
        try {
            final Partner partner = partnersService.getPartner(id);
            if (partner != null) {
                response.setData(partner);
                response.setMessage("Partner retrieved successfully.");
            } else {
                response.setMessage("Partner not found.");
                response.setStatusCode(4000);
                response.setStatus(false);
                httpStatus = HttpStatus.NOT_FOUND;
            }
        } catch (Exception ex) {
            response.setStatus(false);
            response.setMessage(ex.getMessage());
            response.setStatusCode(4000);
            httpStatus = HttpStatus.BAD_REQUEST;
        }
        return new ResponseEntity<>(response, httpStatus);
    }
}

Everything is pretty much default configuration. After a while of use in production, I get:

Mar 09 09:18:22 52.43.134.45-1 partners: 2020-03-09 16:18:22.449  WARN 1 --- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 08S01
Mar 09 09:18:22 52.43.134.45-1 partners: 2020-03-09 16:18:22.449 ERROR 1 --- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper   : HikariPool-1 - Connection is not available, request timed out after 30000ms.

This is running in AWS as a docker image.

Are there known issues or configuration that is not configured out of the box that might be causing this?

kailoon
  • 2,131
  • 1
  • 18
  • 33

0 Answers0